[Fixed]-What does "Directory indexes are not allowed here." mean in a Django error?

11👍

Check your settings.py file for the STATIC_URL value. You want the value to be the subfolder where your static files are stored – generally STATIC_URL = '/static/'.

3👍

The answer depends on which django version you are using. For 1.4+ then just set the STATIC_URL

For 1.3.x its not so much what the STATIC_URL is set to as what your ADMIN_MEDIA_PREFIX is set to.

If you set it to /admin/ then django development server will attempt to serve static files for everything under /admin/ out of the contrib/admin/media/ folder

This means that http://127.0.0.0:8000/admin/postz/post/473 will attempt to find static content at django/contrib/admin/media/postz/post/473 and that’s what the 404 is

If you are trying to access http://127.0.0.0:8000/admin/ then that would be an index.html inside of the admin media directory but the internal static server does not allow indexes so that’s the error that it throws.

The accepted answer isn’t exactly correct. Setting STATIC_URL may have worked as a side effect, but the real issue was that ADMIN_MEDIA_PREFIX was wrong.

The best settings would be:

ADMIN_MEDIA_PREFIX = '/media/' 

or

ADMIN_MEDIA_PREFIX = '/admin/media/'

For 1.4 then just set the STATIC_URL as ADMIN_MEDIA_PREFIX is deprecated

https://docs.djangoproject.com/en/dev/releases/1.4/#django-contrib-admin

0👍

I had the same problem sometime ago and I also was looking for an answer but couldn’t find anything useful. However, the problem for me was the the name I entered in the path in the urls file in my app didn’t match the name of the function in views.

 path('home-en', views.home_en, name="home")

Here ‘home-en’ should’ve been ‘home_en’ to match the name of the view function.

0👍

The reason for getting this error is that maybe trying to map our view with a custom url which luckily is a directory name.
so in this case, for e.g: we’re storing our all static files in Static named folder and we’re trying to create a url : path(‘static/’,views.static_view).
So in this case it will not work.
what we can do, we can change the custom url to any generic url such as ‘inex/’ and it will work.

👤jai

Leave a comment