也许看起来是发生了Django模板语法错误。
我将url设置为动作属性 在下面的表单标签中
<form method="post" id="comment_form" action={% url "blog:comment_new" %}>
<div class="form-group">
{% csrf_token %}
{{ comment_form }}
<input type="submit" class="btn btn-outline-primary">
</div>
</form>
错误状态: 此代码发生错误: 操作= {%url“ blog:comment_new”%}
请求网址时发生错误: 网址:http://127.0.0.1:8000/blog/1/
错误消息: 在/ blog / 1 /
处发生NoReverseMatch错误我不 知道为什么。 谢谢,如果您能告诉我如何解决它。
答案 0 :(得分:1)
您需要将pk作为关键字参数传递。
(?P<pk>\d+)
在将pk作为关键字参数传递时,应使用此格式。
{% url "blog:comment_new" object.pk %}
在这部分代码中,您需要放置对象的pk。