将django与邮递员一起使用{“详细信息”:“ CSRF失败:CSRF令牌丢失或不正确。”}

编程入门 行业动态 更新时间:2024-10-24 16:29:56
本文介绍了将django与邮递员一起使用{“详细信息”:“ CSRF失败:CSRF令牌丢失或不正确。”}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用邮递员检查来自django-rest-framework的json响应。

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

当我第一次尝试通过POST方法将ID,电子邮件,密码发布到我在AWS上的django(亚马逊网络服务),效果很好。它返回如下:

When my first try to post id, email, password through POST method to my django on AWS(amazon web services), it works well. It returned like:

{ "key": "99def123123123123d88e15771e3a8b43e71f" }

但是在第一次尝试后,换句话说,从第二次尝试返回

But after first try, the other words, from second try it returned

{"detail":"CSRF Failed: CSRF token missing or incorrect."}

(附加编辑+)我的腻子终端说 POST / rest-auth / login / HTTP / 1.1 403 58

(Additionally edit +) My putty terminal says "POST /rest-auth/login/ HTTP/1.1" 403 58

我看到了 kechengpuzi/q/s31108075 ,但这不适用于我的情况。

I saw kechengpuzi/q/s31108075, but it is not proper to my case.

并来自 django-rest-framework.narkive/sCyJk3hM/authentication-ordering-token-vs-session ,我找不到解决方案哪个正在使用邮递员

and from django-rest-framework.narkive/sCyJk3hM/authentication-ordering-token-vs-session, i can't find solution which is using postman

  • 如何正确使用邮递员?

  • How can i use postman appropriately?

    还是可以推荐使用其他工具?

    Or Could you recommend other tools to use?

    我正在使用retrofit2制作android应用程序,因此我需要工具来检查POST,GET方法和响应。

    I'm making android application with retrofit2 So I need tools to check POST, GET method and responses.

    推荐答案

    您的api需要CSRF令牌,您必须将CSRF令牌添加到请求(和邮递员)中:

    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" }

    您可以从表单输入字段中获取CSRF令牌(如果使用django,则会找到隐藏字段内置表单api),或者如果您使用Ajax,则可以查看跨站点请求伪造保护。 $ a与您的授权密钥无关,您的密钥用于识别您的身份,CSRF令牌用于确保此请求是从服务器发送的。

    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.

  • 更多推荐

    将django与邮递员一起使用{“详细信息”:“ CSRF失败:CSRF令牌丢失或不正确。”}

    本文发布于:2023-10-29 04:03:00,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1538670.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:详细信息   邮递员   令牌   或不   正确

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!