環境: python 3.4.3 django-1.8.2
在展示詳細內容時出現這個異常:
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]+)/$']
其中有關的文件如下:
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})
當把index.html中的內容改成如下時,則沒有這個異常
<h1 class="title transition"><a href="qs/{{item.id}}/">{{item.brief}}</a></h1>
但是按照django的規范中,還是最開始的寫法符合,但是卻一直報異常,google未果,所以求幫助
添加回答
舉報
0/150
提交
取消