2013-02-20 130 views
-1

我正在设计一个照片应用程序。Django找不到页面(404)

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

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/' 

我认为这个问题是这些设置。我正在使用窗口btw

+0

如何我们的观点成立? urls.py中?什么? – Neal 2013-02-20 15:42:13

+0

他们没有。但我只是从我的管理页面显示图片 – donkeyboy72 2013-02-20 15:47:26

回答

2

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

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, 
     }), 
    ) 

OR

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)