Skip to content Skip to sidebar Skip to footer

Django Admin Wont Load Certain Static Files

I have a strange issue that's occurred on several django projects and I'm trying to figure out a fix for it. For some reason, all the static files for the admin area load properly

Solution 1:

So I was able to answer my own question in the end and for anyone else that comes across this problem here are the steps I took.

For the admin static files, before you run collect static are being sourced directly from the wherever your python(versionNumber)/site-packages/django/contrib/admin/static is located. Unless you run collect static, or manually copy and paste them into your static files directory, these admin files wont be there.

Now I'm sure this is basic knowledge for any django user and I even did this and the error still persisted. What I found, is that I set my static urls up like:

STATIC_URL = '/static/'STATIC_ROOT = os.path.join(BASE_DIR, 'static')

And for some reason, django was still sourcing the admin files from that same directory the django source is located. So I simply changed the url path and static root to:

STATIC_URL = '/staticfiles/'STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

And ran manage.py collectstatic again and that fixed my admin area and everything is working properly now.

Solution 2:

These two files are introduced in django 3.1 for nav_sidebar feature. In admin/base.html, it says:

{% if not is_popup and is_nav_sidebar_enabled %}
  <link rel="stylesheet"type="text/css" href="{% static "admin/css/nav_sidebar.css" %}">
  <script src="{% static 'admin/js/nav_sidebar.js' %}" defer></script>
{% endif %}

is_nav_sidebar_enabled by default is enabled. Did you put something in the root urls.py to disable that?

something like: admin.site.enable_nav_sidebar = False in your root urls.py?

The doc about the new nav_sidebar feature is here

Post a Comment for "Django Admin Wont Load Certain Static Files"