Nho*_*hor 1 python media django debugging media-url
如主题中所述,我的Django站点媒体网址在尝试访问后返回404.在我想要结束开发过程并设置之前,一切都在完美无瑕
DEBUG = True
Run Code Online (Sandbox Code Playgroud)
在settings.py中,让网站一劳永逸地完成.当我改变DEBUG时
DEBUG = False
Run Code Online (Sandbox Code Playgroud)
它再次正常工作.我不知道有什么问题,有什么建议吗?
这是设计的:https://docs.djangoproject.com/en/1.7/howto/static-files/#serving-static-files-during-development
如果您使用django.contrib.staticfiles,如上所述,当DEBUG设置为True时,runserver将自动执行此操作.
话虽这么说,您可以通过修改以下内容来使用以下解决方法urls.py:
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = patterns('',
# ... the rest of your URLconf goes here ...
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Run Code Online (Sandbox Code Playgroud)
请注意,这是非常低效的,不鼓励生产使用.您通常应该配置Web服务器(apache,nginx等)来提供静态和媒体内容.