Hi there,
I'm trying to get to the bottom of this warning that I am getting:
/usr/local/lib/python2.7/site-packages/django/template/defaulttags.py:59: UserWarning: A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext.
warnings.warn("A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext.")
My setup is that I have a form that I am passing to my views via AJAX. I prepare the AJAX POST following the guidelines at:
I am then returning the response using:
return HttpResponse(json.dumps(data), content_type="application/json")
The data returned in the response is then used to update the template that also includes the form.
From the warning I guess I am not returning the CSRF token in the response? Is that the issue? I did try adding the @ensure_csrf_cookie decorator to the views function but still got this warning. Should I manually return a RequestContext and modify my javascript to handle the token accordingly? Apologies - it's the first time I've done anything like this...
Many thanks for any help or light anyone can shed on this.