2

I was working on my development server without problems, when I tried it in my production server, in a real name, not localhost nor ip, I got:

    Forbidden (403)

CSRF verification failed. Request aborted.
Help

Reason given for failure:

    CSRF cookie not set.

I'm sending my post via jquery, used the javascript fix to post method and all...

Dunno what else to do... could anyone give me a hand?

Thanks a lot!

Uriel Bertoche
  • 883
  • 2
  • 13
  • 23

1 Answers1

1

That the cookie is not set usually means you didn't add the csrf middleware. Add that in the relevant settings module for your production deployment. You will also need to make sure the receiving view works when used via javascript.

You have two options. Either mark the view on the server as csrf_exempt or you need to include a csrf token with your request. The csrf token is available to any template as {% csrf_token %}. I would do the latter.

To include the csrf token in your request you just need to pass it as a POST variable csrf_token. You can just have a snippet in a template like this one:

<script type="text/javascript">
    var csrf_token = '{% csrf_token %}';
</script>

And wherever you are making a request, just add "csrf_token": csrf_token, to the post data.

rz.
  • 19,861
  • 10
  • 54
  • 47