Django media files doesn't work when debug=false

寵の児 提交于 2019-11-28 14:37:17

static helper function does not work in DEBUG=False mode. And should not. Serving static/media files with Django in prod is not recommended. Configure your webserver (Nginx, Apache,..) to serve these files.

error 500 - investigate log files to understand what causes app failure. static file are serve successfully perhaps they are being taken from browsers cache.

I had been Using WhiteNoise which allows your web app to serve its own static files, making it a self-contained unit that can be deployed anywhere without relying on nginx, Amazon S3 or any other external service.

1 - Install with pip:

pip install whitenoise

2 - Edit your settings.py file and add WhiteNoise to the MIDDLEWARE_CLASSES list, above all other middleware apart from Django’s SecurityMiddleware:

MIDDLEWARE = [
  # 'django.middleware.security.SecurityMiddleware',
  'whitenoise.middleware.WhiteNoiseMiddleware',
  # ...
]

Thats All you need to serve static files without configuring any third party server.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!