NoReverseMatch at /app/detail/3/
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['app/detail/(?P<pk>[0-9]+)/$']
とエラーが出ました。
https://torina.top/detail/369/
を参考にしながらコメント返信機能を作っています。
views.pyに
def top(request): content = POST.objects.order_by('-created_at')[:5] page = _get_page(blog_content, request.GET.get('page')) return render(request, 'top.html',{'content':content,"page":page}) class DetailView(generic.DetailView): model = POST template_name = 'detail.html'
と書き、top.htmlに
<div> {% for content in page %} <h2>{{ content.title }}</h2> <p><a href="{% url 'detail' content.pk %}">SHOW DETAIL</a></p> {% endfor %} </div>
と書き、detail.htmlに
<div> <h2>Comment List</h2> <a href="{% url 'comment' pk %}">Comment</a> {% for comment in post.comment_set.all %} Name:{{ comment.name }} <br> Text:{{ comment.text }} <br> <a href="{% url 'recomment' comment.pk %}">Reply</a> <br> {% endfor %} </div> <div> <h2>Comment Form</h2> <form action="" method="POST"> {{ form.as_p }} {% csrf_token %} <button type="submit">Send</button> </form> </div>
と書き、urls.pyに
urlpatterns = [ path('top/', views.top, name='top'), path('detail/<int:pk>/', views.DetailView.as_view(template_name='detail.html'), name='detail'), path('comment/<int:pk>/',views.comment, name='comment'), path('recomment/<int:pk>/', views.recomment, name='recomment'), ]
と書きました。top.htmlにアクセスした時はウェブサイトは正常に動きましたが、SHOW DETAILリンクを押すとこのエラーが起きました。
<a href="{% url 'comment' pk %}">Comment</a>
の部分がおかしいと言われているのですが。。。どう直せば良いのでしょうか?
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/01/05 04:14