[Django]-CSRF token missing or incorrect โ€“ Django

4๐Ÿ‘

โœ…

Please put {% csrf_token %} inside <form> tag. This will solve the issue.

๐Ÿ‘คShamir Imtiaz

2๐Ÿ‘

{% csrf_token %} should be inside the form tag.
like this

<form action="." method="POST">
{% csrf_token %}
       <input type="text" name="eur" placeholder="EUR">
       <input type="submit">
</form>

The reason behind that is because {% csrf_token %} is rendered like this, and inorder input to be submitted along with form it needs to be inside form element.

<input type="hidden" name="csrfmiddlewaretoken" value="0gdrskkUXOTenFZOWxhzQPZWavohLKrEaOm0aKj8KzOfeLFah9PihEdYG24Fl4F7">```
๐Ÿ‘คRahul Palve

1๐Ÿ‘

You need to put {% csrf_token %} inside the <form> tag like this:

<form action="." method="POST">
    {% csrf_token %}
    <input type="text" name="eur" placeholder="EUR">
    <input type="submit">
</form>
๐Ÿ‘คuser15256253

1๐Ÿ‘

There is error in your form file, your csrf_token is expected to be inside your tag because django is expecting it with the form data as to certify that what you are sending is safe. Try this

   <form action="." method="POST">
          {% csrf_token %}
           <input type="text" name="eur" placeholder="EUR">
           <input type="submit">
     </form>

It will work that way.

๐Ÿ‘คsamkayz

Leave a comment