![](/img/trans.png)
[英]Django: Stop redirecting URL to another page after setting it with permanent=True
[英]Python Django media url not working after setting DEBUG = True
如主題所述,我的Django網站媒體網址在嘗試訪問后返回404。 一切工作都完美無缺,直到我想結束開發過程並確定
DEBUG = True
在settings.py中使網站一勞永逸。 當我將調試更改回
DEBUG = False
它再次正常工作。 我不知道出什么問題了,有什么建議嗎?
這是設計使然 : 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)
注意,這是非常低效的,不建議用於生產。 通常,您應該配置Web服務器(apache,nginx等)以提供靜態和媒體內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.