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

后端 未结 14 2078
忘了有多久
忘了有多久 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:55

    You actually can serve static files in a production Django app, securely and without DEBUG=True.

    Rather than using Django itself, use dj_static in your WSGI file (github):

    # requirements.txt:
    
    ...
    dj-static==0.0.6
    
    
    # YOURAPP/settings.py:
    
    ...
    STATIC_ROOT = 'staticdir'
    STATIC_URL = '/staticpath/'
    
    # YOURAPP/wsgi.py:
    
    ...
    from django.core.wsgi import get_wsgi_application
    from dj_static import Cling
    
    application = Cling(get_wsgi_application())
    

提交回复
热议问题