django handling requests - getting CSRF verification failed. Request aborted.

17 views
Skip to first unread message

Shekar Tippur

unread,
May 28, 2015, 9:31:23 AM5/28/15
to django...@googlegroups.com
Hello,

I am trying to post a request via curl. I get a CSRF verification failed message.

Here is the entry in my urls.py

url(r'^setProfile/', AddToUserProfile),

class AddToUserProfile(generics.ListAPIView):
queryset = UserPrefs.objects.all()
serializer_class = UserPrefSerializer

class UserPrefSerializer(serializers.ModelSerializer):
class Meta:
model = UserPrefs
fields = ('id', 'prefs', 'obj_id', 'user_id')
depth = 1

I have read on previous posts that I need to add a context_instance=RequestContext(request)

How do I add it and what is the right way to handle this?

- Shekar

Larry Martell

unread,
May 28, 2015, 9:42:33 AM5/28/15
to django...@googlegroups.com
I have done it like this:

curl -H "Cookie: csrftoken=mycsrfToken" -X POST -d
'csrfmiddlewaretoken= mycsrfToken&...'

Shekar Tippur

unread,
May 28, 2015, 9:52:52 AM5/28/15
to django...@googlegroups.com
Larry,

I think I needed to append as_view() to the url.

url(r'^setProfile/', AddToUserProfile.as_view()),

I will try the other curl option as well.
Reply all
Reply to author
Forward
0 new messages