[英]django CSRF token missing or incorrect error but it is included
I have the following django formset represented in the template: 我在模板中具有以下django表单集:
<form method="post" action="">
{% csrf_token %}
{{ formset.management_form }}
{% csrf_token %}
<table width="100%" border="0" cellspacing="0" cellpadding="0">
{% for form in formset %}
{% csrf_token %}
<tr>
<th>My Activities</th>
<th>Duration</th>
<th>Log</th>
</tr>
<tr>
<td>{{ form.instance.activity.name }}</td>
<td><input type="text" class="minutesinput"> Minutes</td>
<td>
<div class="actvty_log_entry">
<input type="submit" value="Log Entry">
</div>
</td>
</tr>
{% endfor %}
</table>
</form>
When I submit the form, I get the error: 提交表单时,出现错误:
Forbidden (403)
CSRF verification failed. Request aborted.
Note: my normal forms work in all my other views and the middleware is activated 注意:我的普通表单可以在所有其他视图中使用,并且中间件已激活
The problem was I was using render to response instead of: 问题是我使用渲染而不是:
return render(request, 'customers/password-change.html', context)
Changing to the above worked. 更改为上述工作。 Thanks for the hint @Daniel Roseman 感谢您的提示@Daniel Roseman
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.