无法访问Python中的HTTP POST授权令牌

2024-10-02 04:23:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在构建一个djangojwtapi并完成登录/注销/注册路由。我正在尝试创建一个新的路由,该路由接受来自经过身份验证的用户的post请求中的json数据,并最终将其添加到用户的数据库中。你知道吗

我正在用Postman测试这个路由,发送头中的Authroization键以及json数据。在我的视图.py我可以成功地识别post请求并打印json数据,但是在任何地方都找不到授权头。如果我想打印出来请求.headers'它说“AttributeError:'WSGIRequest'对象没有属性'headers'”

你知道吗视图.py地址:

def HomePageView(请求):

if request.method=='POST':
    print('its a post')
    print('request: ' + str(request))
    print('request.body: ' + str(request.body))
    print('request.method: ' + str(request.method))
    print('request.headers: ' + str(request.headers))

    return StreamingHttpResponse('response')  

邮递员: enter image description here

enter image description here

错误: enter image description here


Tags: 数据用户py身份验证视图json路由request

热门问题