1
我不能爲了我的生活找出爲什麼我的URL配置不會指向django中的頁面。Django url confs不會匹配
我想在底部訪問錯誤信息中顯示一個URL(無法得到逃避的鏈接,抱歉)
YellowOrangeFoxZebra是一個有效的imgID,在模型中正確定義。
imgApp/urls.py
from django.conf.urls import patterns, url
from imgApp import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^(?P<imgID>\d+)/$', views.detail, name='detail'),
)
views.py
def detail(request, given_image_ID):
image = get_object_or_404(imgAppImage, imgID=given_image_ID)
return render(request, 'imgApp/detail.html', image)
detail.html
<img src="{{ image.imgFile.url }}" >
錯誤消息,我回去了Django的是:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/imgApp/YellowOrangeFoxZebra/
Using the URLconf defined in thatSite.urls, Django tried these URL patterns, in this order:
^imgApp/ ^$ [name='index']
^imgApp/ ^(?P<imgID>\d+)/$ [name='detail']
^imgApp/ ^(?P<pk>\d+)/results/$ [name='results']
^imgApp/ ^(?P<question_id>\d+)/vote/$ [name='vote']
^admin/
^media/(?P<path>.*)$
The current URL, imgApp/YellowOrangeFoxZebra/, didn't match any of these.
你爲什麼使用'\ d +'? – 2014-11-02 15:49:12
因爲它在本教程中使用過,所以我不知道它的含義。這是我第一次用正則表達式。 – Jon 2014-11-02 16:04:15
嘗試'^ imgApp/\ w +/$' – 2014-11-02 16:06:11