Created
February 16, 2014 13:05
-
-
Save jhrr/9033927 to your computer and use it in GitHub Desktop.
Embed the CSRF token in a meta tag in the HTML header, and to modify Sync to take the token from the DOM and add it to the AJAX request's HTTP headers. From: http://ozkatz.github.io/backbonejs-with-django-15.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var oldSync = Backbone.sync; | |
Backbone.sync = function(method, model, options){ | |
options.beforeSend = function(xhr){ | |
xhr.setRequestHeader('X-CSRFToken', CSRF_TOKEN); | |
}; | |
return oldSync(method, model, options); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- inside our page's <head> tag --> | |
<meta name="csrf-token" content="{{csrf_token}}"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment