My current setup is AngularJS + Django 1.5, and I completely abandoned the use of the Django template engine (i.e. the backend is pretty much an API server).
Since I do not use the template tag csrf_token, Django, in turn, does not set or send a cookie csrftokenin response. As stated in the official docs, the decorator ensure_csrf_cookie()should be used to make the decorated look send a cookie csrftoken.
I applied a decorator ensure_csrf_cookie()to a view that serves the first GET request that my web client calls upon boot. At the same time, my web client receives a CSRF trick and is now allowed to call unsafe methods (like POST) to the server.
The above setting works fine only if the CSRF token remains the same until the browsing session ends.
Question: Does the Jango CSRF token mean during a browsing session? If yes, does this mean that I will need to apply the decorator ensure_csrf_cookie()to all the representations that I have?
source
share