Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

django

I am trying to debug this bizarre 404 error that surfaced in my Django application.

Page not found (404)
Request Method: GET
Request URL:    http://78.198.124.245/
Directory indexes are not allowed here.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

What does "Directory indexes are not allowed here." mean? What is a directory index?

I Googled around, and the results I found all have to do with serving static files. However, I don't think I do that. What does this error mean?

like image 761
dangerChihuahua007 Avatar asked May 17 '12 23:05

dangerChihuahua007


2 Answers

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/'.

like image 118
Dan Hoerst Avatar answered Oct 17 '22 01:10

Dan Hoerst


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

like image 35
Chris Sattinger Avatar answered Oct 17 '22 01:10

Chris Sattinger