我在我的开发服务器上设置了以下 URL 模式。调试 = 真。我的媒体目录上的图像链接不起作用(即 localhost/media/images/img1.jpg 不加载图像)。但是,如果我在注释为 MAIN URL PATTERNS 的部分前面插入媒体 url 模式,它就可以工作,这表明我的媒体链接设置正确。这里发生了什么?
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,}),
)