我的urls.py
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'photo.views.home', name='home'),
# url(r'^photo/', include('photo.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += patterns('django.views.static',
(r'media/(?P<path>.*)$', 'serve', {'document_root': settings.MEDIA_ROOT}),
)
Settings.py
MEDIA_ROOT = 'E:/photo/media'
MEDIA_URL = '/media'
STATIC_ROOT = ''
STATIC_URL = '/static/'
ADMIN_MEDIA_PREFIX = '/static/admin/'
当我尝试访问用户上传的图片时,它会出现以下错误。
Using the URLconf defined in photo.urls, Django tried these URL patterns, in this order:
^admin/doc/
^admin/
media/(?P<path>.*)$
The current URL, images/about-landscapes-nature.jpg, didn't match any of these.
我做错了什么? 用户上传的图像将存储在photo \ media \ images
中以下是我的Win7中的目录结构
photo
media
photoapp
models.py
settings.py
urls.py
答案 0 :(得分:0)
我不确定这是否能解决所有问题,但MEDIA_URL
需要一个尾随斜杠,所以应该是:
MEDIA_URL = '/media/'