Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django CSRF令牌丢失或错误,但已包含在内_Python_Django_Http Status Code 403_Django Forms - Fatal编程技术网

Python django CSRF令牌丢失或错误,但已包含在内

Python django CSRF令牌丢失或错误,但已包含在内,python,django,http-status-code-403,django-forms,Python,Django,Http Status Code 403,Django Forms,我在模板中表示了以下django表单集: <form method="post" action=""> {% csrf_token %} {{ formset.management_form }} {% csrf_token %} <table width="100%" border="0" cellspacin

我在模板中表示了以下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>

注意:我的正常表单在我的所有其他视图中工作,中间件被激活

问题是我使用的是“渲染到响应”,而不是:

return render(request, 'customers/password-change.html', context)

换成上面的方式是有效的。谢谢@Daniel Roseman的提示

那么,您是否查看了错误页面上解释可能发生这种情况的文本?这里会有这样的情况吗?通常的问题是在呈现模板时无法使用RequestContext。为什么表单中有3次csrf_令牌?
return render(request, 'customers/password-change.html', context)