python - How to make a Django-Rest-Framework API that takes POST data? -


i'm building django application django-rest-framework apis. have built api endpoint follows. want able post data browser. want retrieve object model database has matching primary given in url. , want operate on retrieved object based on data posted browser. if grab posted data viewset, done. don't know how execute viewset's update() function when post.

from urls.py file:

router.register(r'replycomment', views.replycomment, base_name="replycomment") 

from views.py file:

class replycomment(viewsets.viewset):     def update(self,request,pk=none):         try:              origcomment = comment.objects.get(pk=pk)             # here modifies state of origcomment , saves it.             return response(                 json.dumps(true),                  status=status.http_200_ok,             )         except exception exception:             logger.error(exception)             return response(status=status.http_400_bad_request) 

i'm using advanced rest client (arc) tool in chrome browser. when point arc tool http://127.0.0.1:3001/api/replycomment/2/ using post method, error:

{     detail: "csrf failed: csrf token missing or incorrect".  } 

see screenshot here. seems i'm doing wrong here post. can please advise how properly? how can around csrf issue? i'm newbie django rest frameworks. if can provide clear details, appreciated. please let me know changes need make ensure post works intend to? need bit more referring me manual. (i tried still couldn't make work)

csrf tokens required in django protect against csrf(cross site request forgery). methods writes (post, put, delete etc), need include csrf token request django knows request came own site.

you can read more in django-rest-framework documentation. , says in doc, can find how include csrf token in http header in django documentation.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -