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

前端 未结 2 1831
旧时难觅i
旧时难觅i 2021-01-17 12:16

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.12         


        
相关标签:
2条回答
  • 2021-01-17 12:42

    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 讨论(0)
  • 2021-01-17 12:59

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

    0 讨论(0)
提交回复
热议问题