没有证词与给定查询匹配

时间:2019-01-31 05:08:23

标签: django

我正在尝试为每个具有有效ID的实例设置注释功能。但是,通过点击下面的链接,我得到了“没有证词匹配给定的查询”。enter image description here 任何帮助表示赞赏。

模板

<a href="{% url 'commentform' testimony.id %}">Make a comment</a>

网址

urlpatterns = [
    ...
    path('<int:id>/commentform/', views.CommentForm, name='commentform'),
]

观看次数

def CommentForm(request, id=None):
    print('1')
    testimony=get_object_or_404(Testimony, id=id)
    print('2')
    print('3')
    form=CommentForm(request)
    if request.method=='POST':
        form=CommentForm(request.POST or None, request.FILES or None)
        print('d')
        if form.is_valid():
            print('e')
            comment=form.save(commit=False)
            comment.testimony=testimony
            comment.save()
            return redirect('details', id=testimony.id)
        else:
            form=CommentForm(request.POST or None, request.FILES or None)
    return render(request, 'comment_form.html', {'form':form})

0 个答案:

没有答案