简体   繁体   中英

django CSRF token missing or incorrect error but it is included

I have the following django formset represented in the template:

<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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM