我在開發服務器上設置了以下URL模式。 DEBUG = True。我的媒體目錄上的圖像鏈接不起作用(即localhost/media/images/img1.jpg不會加載圖像)。但是,如果我在註釋MAIN URL PATTERNNS部分前面插入媒體url模式,則表明我的媒體鏈接設置正確。這裏發生了什麼?開發服務器上的Django媒體文件
urlpatterns = patterns("",
# works if I insert the media url pattern here
# MAIN URL PATTERNS
(r"^admin/" , include(admin.site.urls)),
(r"^group/(?P<dpk>\d+)/(?P<show>\S+)/" , GroupView.as_view(), {}, "group"),
(r"^group/(?P<dpk>\d+)/" , GroupView.as_view(), {}, "group"),
(r"^add-images/(?P<dpk>\d+)/" , AddImages.as_view(), {}, "add_images"),
(r"^slideshow/(?P<dpk>\d+)/" , SlideshowView.as_view(), {}, "slideshow"),
(r"^image/(?P<mfpk>\d+)/" , ImageView.as_view(), {}, "image"),
(r"^image/" , ImageView.as_view(), {}, "image"),
(r"" , Main.as_view(), {}, "photo"),
# END OF MAIN URL PATTERNS
)
if settings.DEBUG:
urlpatterns += patterns('',
(r'^media/(?P<path>.*)$','django.views.static.serve',{'document_root': settings.MEDIA_ROOT,}),
)
該文檔明確建議要前置靜態文件視圖到你的urlpatterns。 – dom0