My current setup is AngularJS + Django 1.5 and I have completely thrown away the use of Django's template engine (ie. the backend is pretty much an API server).
Since I am not using the csrf_token
template tag, Django, in turn, does not set and send the csrftoken
cookie in response. As instructed by the official docs, the ensure_csrf_cookie()
decorator should be used to force the decorated view to send the csrftoken
cookie.
I have applied the ensure_csrf_cookie()
decorator to the view, which serves the first GET request that my web client calls at bootstrapping. With that, my web client gets a hold of the CSRF token and henceforth is allowed to call unsafe methods (ex. POST) to the server.
The above setup works fine only if the CSRF token remains the same until the browsing session ends.
Question: Does Django's CSRF token get updated during the course of a browsing session? If 'yes', does that mean I would need to apply the ensure_csrf_cookie()
decorator to all the views I have?