您没有将
news对象传递到 news_detail.html 的上下文中。您可以通过传递
news和执行
{{ news.title}}模板中的操作(而不是{{ title }})来大大简化视图:def newsDetailView(request, news_pk): news = get_object_or_404(News, id=news_pk) tags = news.tag.annotate(news_count=Count('news')) all_comments = NewsComments.objects.filter(news=news) return render(request, "news_detail.html", { 'news': news, 'tags': tags, 'all_comments': all_comments, })现在
news.pk将作为
{% url ... %}标签的参数。我还确保如果news找不到对象(在您的代码中,它将崩溃),则会生成404错误。


![找不到带有参数“('',)”的“ update_comment”。尝试了1个模式:['comment \ /(?P[0-9] +)$'] 找不到带有参数“('',)”的“ update_comment”。尝试了1个模式:['comment \ /(?P[0-9] +)$']](http://www.mshxw.com/aiimages/31/517195.png)
