栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

找不到带有参数“('',)”的“ update_comment”。尝试了1个模式:['comment \ /(?P[0-9] +)$']

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

找不到带有参数“('',)”的“ update_comment”。尝试了1个模式:['comment \ /(?P[0-9] +)$']

您没有将

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错误。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/517195.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号