Django CSRF Verifcation failed - Class based views -


i'm using class-based views.

class usercreate(view):     def post(self, request):         data = request.data.get         social_id = data('social_id')         social_source = data('social_source')         user = user(social_id=social_id, social_source=social_source, access_token=access_token)         user.save()         return jsonresponse({'response':200}) 

whenever post data on url, says csrf token missing or incorrect.

curl -x post --header "content-type: application/json" --header "accept: application/json" -d "{   \"social_id\": \"string\",   \"social_source\": \"fb/gmail\",   \"access_token\": \"string\" }" "http://127.0.0.1:8000/users/" 

i've had problem while getting data form in function views. there used add @csrf_exempt on view , work. when added @csrf_exempt post method, not work. how can post data?

this because class_based views need decorate dispatch method csrf_exempt work

class usercreate(view):   @method_decorator(csrf_exempt)   def dispatch(self, request, *args, **kwargs):     return super(usercreate, self).dispatch(request, *args, **kwargs)    def post():   .... 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -