環(huán)境: python 3.4.3 django-1.8.2
在展示詳細(xì)內(nèi)容時(shí)出現(xiàn)這個(gè)異常:
NoReverseMatch at /
Reverse for 'detail' with arguments '()' and keyword arguments '{'pk_id': 2}' not found. 1 pattern(s) tried: ['$qs/(?P<pk_id>[0-9]+)/$']
其中有關(guān)的文件如下:
index.html
{% for item in post_latest %}
<h1 class="title transition"><a href="{% url 'detail' pk_id=item.pk %}">{{item.brief}}</a></h1>
{% endfor %}
urls.py
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^qs/(?P<pk_id>[0-9]+)/$', views.detail, name='detail'),
]
views.py
def detail(request, pk_id):
detail_qs = get_object_or_404(Qs, pk=pk_id)
return render(request, 'qs/node/detail.html', {'detail': detail_qs})
當(dāng)把index.html中的內(nèi)容改成如下時(shí),則沒有這個(gè)異常
<h1 class="title transition"><a href="qs/{{item.id}}/">{{item.brief}}</a></h1>
但是按照django的規(guī)范中,還是最開始的寫法符合,但是卻一直報(bào)異常,google未果,所以求幫助
3 回答

墨色風(fēng)雨
TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超6個(gè)贊
你在外層的 urlpatterns
用了 include
吧?
用 include()
的時(shí)候,請不要加 $
添加回答
舉報(bào)
0/150
提交
取消