Media files not showing on Debug False

Deadly 提交于 2019-12-25 16:49:44

问题


I've just deployed a site with pythonanywhere, when I set to DEBUG mode to False, my media images dissapear, the path of my media folder is not found. I was asking myself what causes this issue and how I can resolve it ?

Here is how I configured my settings :

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

urls.py

urlpatterns = [
    ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

回答1:


The behaviour you are seeing is by design, Django doesn't serve static files in production mode. Serving many, potentially huge static files using Python will put a lot of stress on the server, while any of the common servers will handle that with ease.

Hence you need to serve them using Apache or nginx yourself: https://docs.djangoproject.com/en/1.10/howto/static-files/deployment/




回答2:


Found it, with pythonanywhere I had to setup media on the static files handler like this :

path : /media/

directory : /home/<myusername>/<myproject>/media

Then reload the domain name after setting DEBUG to False.



来源:https://stackoverflow.com/questions/42505292/media-files-not-showing-on-debug-false

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