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

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

    You can use WhiteNoise to serve static files in production.

    Install:

    pip install WhiteNoise==2.0.6
    

    And change your wsgi.py file to this:

    from django.core.wsgi import get_wsgi_application
    from whitenoise.django import DjangoWhiteNoise
    
    application = get_wsgi_application()
    application = DjangoWhiteNoise(application)
    

    And you're good to go!

    Credit to Handlebar Creative Blog.

    BUT, it's really not recommended serving static files this way in production. Your production web server(like nginx) should take care of that.

提交回复
热议问题