4👍
✅
Add {% csrf_token %}
as normal then add a pre-request callback function beforeSend on your AJAX POST etc:
beforeSend: function (request) {
request.setRequestHeader("X-CSRFToken",
$('input[name="csrfmiddlewaretoken"]').val());
},
If using an API Framework like TastyPie you have other options for authentication. See here: How can I login to django using tastypie
Source:stackexchange.com