CSRF verification failed. Request aborted.

3,161 views
Skip to first unread message

Matin Shah

unread,
Sep 21, 2016, 3:28:04 AM9/21/16
to Wagtail support
I have created a contact form from wagtail built in form. I have added secrete keys to development an production settings. In development mode, form submits smoothly, but during production mode it fails with the following error. Any word of advice. Thanks you all.

This is my html output:

<form action="/contact-us/" method="POST">

<input type='hidden' name='csrfmiddlewaretoken' value='s6tjjlkjlkjkljl;kjl;kj lk huiyiuykjhjkh kmUwAdiO58RwbWiCMpCFPSNQpxRI' />
<p><label for="id_name">Name</label> <input id="id_name" maxlength="255" name="name" type="text" required /></p>
<p><label for="id_email">Email</label> <input id="id_email" name="email" type="email" required /></p>
<p><label for="id_phone">Phone</label> <input id="id_phone" maxlength="255" name="phone" type="text" /></p>
<p><label for="id_message">Message</label> <textarea cols="40" id="id_message" name="message" rows="10" required>
</textarea></p>
<input type="submit" class="btn btn-success btn-sm">
</form>



However instead of submit form, the follow error is rendered:

Forbidden (403)

CSRF verification failed. Request aborted.

You are seeing this message because this site requires a CSRF cookie when submitting forms. This cookie is required for security reasons, to ensure that your browser is not being hijacked by third parties.

If you have configured your browser to disable cookies, please re-enable them, at least for this site, or for 'same-origin' requests.


mronoffon

unread,
Sep 21, 2016, 7:40:52 AM9/21/16
to Wagtail support

 you need this:   {% csrf_token %}
but instead you have:    name='csrfmiddlewaretoken' value='s6tjjlkjlkjkljl;kjl;kj lk huiyiuykjhjkh kmUwAdiO58RwbWiCMpCFPSNQpxRI' ....

<form action="/contactus/" method="POST"> 
{% csrf_token %}

django should be serving up the csrf_token.  is there any reason why you're doing this manually?



Message has been deleted
Message has been deleted

Matin Shah

unread,
Sep 21, 2016, 8:15:48 AM9/21/16
to Wagtail support
I figured it out, I set CSRF_COOKIE_SECURE = True, deleting it solved the problem. Anyhow thanks a lot
Reply all
Reply to author
Forward
0 new messages