简体   繁体   中英

Django Rest frame work “CSRF Failed: CSRF token missing or incorrect.” error on JSONWebTokenAuthentication

I want to send a POST request using POSTMAN and my url is like http://127.0.0.1:8000/restaurant/article/update/23

On login I am sending a token which is Json web token (created like this) https://jpadilla.github.io/django-rest-framework-jwt/#creating-a-new-token-manually

def get_token(user):
    jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
    jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
    payload = jwt_payload_handler(user)
    return jwt_encode_handler(payload)

And on login my api response is like

{
    "success": true,
    "message": "Successfully logged in",
    "data": {
        "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6IkRlbW9AZ21haWwuY29tIiwiZXhwIjoxNjAyNzU1MDE4LCJlbWFpbCI6IiJ9.sgLS4NofzDtdUSHYvuepRruw2PgTPLyGCdjIOiLdrkw",
        "restaurant": {
            "id": 1,
            "image": "/media/Restaurant/Entertainment.jpg",
            "restaurant": "Demo",
        }
    }
}

when I am using this token like this in post man its not working

csrf 令牌丢失

BUT token provided in post man cookie when I use that it works like this.What's going on here? any help would be highly appreciated.

邮递员 cookie 中的图像

Formate to use token is

token : 'jwt token'

token is your token

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM