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

前端 未结 7 2276
谎友^
谎友^ 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:12

    Just in case it may be useful for somebody, I was facing the same problem with Postman. I was asked to include a CSRF on every request after getting a token for the first time so I realized that I had Session and Token authentication methods enabled so I commented out the SessionAuthentication line (of course, you could remove it as well)

    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
        # 'rest_framework.authentication.SessionAuthentication',
    ]
    

    After that, I was able to request a token by using only my credentials without including any CSRF code:

    I think that the fact of having those two auth classes activated was causing Django to muddle up somehow.

提交回复
热议问题