Why does DEBUG=False setting make my django Static Files Access fail?

后端 未结 14 2156
忘了有多久
忘了有多久 2020-11-22 05:16

Am building an app using Django as my workhorse. All has been well so far - specified db settings, configured static directories, urls, views etc. But trouble started sneaki

14条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 05:56

    You can debug this in many different ways. Here's my approach.

    localsettings.py:

    DEBUG = False
    DEBUG404 = True
    

    urls.py:

    from django.conf import settings
    import os
    
    if settings.DEBUG404:
        urlpatterns += patterns('',
            (r'^static/(?P.*)$', 'django.views.static.serve',
             {'document_root': os.path.join(os.path.dirname(__file__), 'static')} ),
        )
    

    Be sure to read the docs ;)

    https://docs.djangoproject.com/en/2.0/howto/static-files/#limiting-use-to-debug-true

提交回复
热议问题