-1

我正在设计一个照片应用程序。

每次我在管理页面上查看上传的图片时都会收到此错误。

 Page not found (404)
 Request Method:    GET
 Request URL:   http://127.0.0.1:8000/media/images/California_Poppy.jpg

 Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

     ^polls/
     ^admin/
     ^cool/
     ^forum/
     ^register/

 The current URL, media/images/California_Poppy.jpg, didn't match any of these.

我当前的设置是:

 MEDIA_ROOT = 'C:/djcode/mysite/photo'


 MEDIA_URL = 'http://127.0.0.1:8000/media/'

我认为问题出在这些设置上。我正在使用窗口顺便说一句

4

1 回答 1

2

Django 文档为您提供了在开发中为媒体提供服务的解决方案。通常在生产中,您可以为您的媒体目录设置别名,以便直接从您的网络服务器提供服务,以提高效率。为了在开发中服务,文档显示了两种不同的解决方案。您可以查看提供的链接以阅读文档并找出哪个更适合您。

from django.conf import settings

# ... the rest of your URLconf goes here ...

if settings.DEBUG:
    urlpatterns += patterns('',
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
            'document_root': settings.MEDIA_ROOT,
        }),
   )

或者

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = patterns('',
    # ... the rest of your URLconf goes here ...
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
于 2013-02-20T16:05:32.610 回答