Hi,

for me the following snippets work:

var testRun = angular.module('testRun', ['ui.bootstrap']);
testRun.config(function($httpProvider) {
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
});

See: 
https://github.com/thoreg/test_executor/blob/master/test_executor/static/js/app.js

Good Luck


2015-03-14 9:14 GMT+01:00 Richard Jeffries <mileendt...@gmail.com>:
> Hi,
>
> Thats pretty much the use case I have (accessing an API with no template). I
> couldn't get angular to play nice even with the below settings so I'd
> resorted to POST-ing the token but then I encountered the POST dict being
> turned into JSON.
>
> Appreciate that this short-coming is not django so will bow down to your
> superior knowledge in this area if you feel this too much of a 'hack'
>
> Thanks
> Richard
>
>
> On Friday, March 13, 2015 at 6:42:36 PM UTC, Rafał Pitoń wrote:
>>
>> On Friday, March 13, 2015 at 4:14:55 PM UTC+1, Florian Apolloner wrote:
>>>
>>> I am pretty sure you can configure angular to send the token in the
>>> header. Either way, we are not going to try and load json, just we can't
>>> find a token otherwise…
>>>
>>> Cheers,
>>> Florian
>>
>>
>> Pretty much, you have to tell Angular to use cookie for token and send
>> CSRF header:
>>
>> $http.defaults.xsrfHeaderName = 'X-CSRFToken';
>> $http.defaults.xsrfCookieName = 'csrftoken';
>>
>> However I would argue that option to always send CSRF cookie would be
>> useful in situations when your app templates contain no {% csrf_token %},
>> yet you need that cookie for API calls from frontend to sign their POST's to
>> backend.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-developers.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/748a910f-e8c0-4c37-bcbb-d907baa00a8a%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAFgu0xjBjZRqQPHW67uz96t%3DzgxPgfwbAK%2BokNQStivOXinGog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to