I\'d like to send an ajax request (via Jquery, although I think that\'s irrelevant in this situation) without using a form element in Django. According to the documentation,
ensure_csrf_cookie
may only be a 1.4 alpha feature if you're having trouble importing it -- I can import it just fine with the same statement on trunk.
The simplest solution here is to pass the csrf_token VALUE in the ajax call itself.
You said you were using jQuery.
$.ajax({
url: "",
type: 'POST',
data: {
csrfmiddlewaretoken: '{{ csrf_token }}' // just the token value
},
success: function(response) {
}
})
It appears this ensure_csrf_cookie
forces the view to set the csrf cookie that would be required for use in the automatic cookie based csrf protection mechanism for jquery ajax calls described here: https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#ajax