Using django with postman {“detail”:“CSRF Failed: CSRF token missing or incorrect.”}

前端 未结 7 2090
谎友^
谎友^ 2021-02-20 17:08

I\'m using postman to check json response from my django-rest-framework.

When my first try to post id, email, password through POST method to my django on AWS(amazon web

7条回答
  •  暖寄归人
    2021-02-20 17:17

    Your api need CSRF token, you have to add CSRF token to the request(and postman):

    data: { csrfmiddlewaretoken: csrf_token, "username": "thesamething", "email": "thesamething", "password": "thesamething" }
    

    You can get CSRF token from your form input field(you will find a hidden field if you use django build-in form api) or if you use Ajax, you can have a look at Cross Site Request Forgery protection.It has nothing to do with your authorization key, your key is use to identify who you are, and CSRF token is to make sure this request is send from your server.

提交回复
热议问题