2013-02-20 174 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)