0

我的网址.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}),
    )

设置.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
4

1 回答 1

0

我不确定这是否能解决你所有的问题,但MEDIA_URL需要一个斜杠,所以它应该是:

MEDIA_URL = '/media/'
于 2013-05-23T03:49:29.903 回答