[Fixed]-Csrf cookie not set django

1๐Ÿ‘

โœ…

You are manually adding the CSRF token to the context, but you are only doing it after the POST. The whole point of a CSRF token is that it is set by the GET, and checked on POST. Since you are not setting it on GET, the POST will fail.

However you should not be setting it manually at all. Django will do it for you, as long as you use a RequestContext. And the way to do that is to use the render shortcut, passing it the request, rather than the old render_to_response.

Remove the call to csrf(request) and replace your last line with:

return render(request, 'authen/auth.html', dic)
๐Ÿ‘คDaniel Roseman

0๐Ÿ‘

In your view.py add RequestContext(request) to render_to_response:

return render_to_response('authen/auth.html',dic, context_instance = RequestContext(request))
๐Ÿ‘คAnush Devendra

0๐Ÿ‘

I was receiving the Forbidden (403), CSRF cookie not set. error. I thought it had something to do with ios.

I fixed this by adding an "s" to the end of http, FROM: http://MYAPPNAME.herokuapp.com/ TO: https://MYAPPNAME.herokuapp.com/

In

# settings.py
SESSION_COOKIE_SECURE = True
๐Ÿ‘คJSotelo

Leave a comment