【问题标题】:Postman POST request returning None in django邮递员 POST 请求在 Django 中返回 None
【发布时间】:2021-04-29 00:15:01
【问题描述】:

我正在尝试使用邮递员将 POST 请求发送到 django 服务器中的 API。 API 是一个 APIView :

class LoginView(APIView):
    
    template_name = 'login.html'
    from_class = LoginForm  

    def post(self, request, format=None):
       
        data = request.data
        username = data.get('username', None)
        password = data.get('password', None)
        print(username)


这是联合图片中的邮递员请求

问题是我总是得到无用户名和密码。 如果您能发现问题,请指导我。

【问题讨论】:

  • 试试这个:将 data.get 更改为 request.POST.get()
  • @ming 它也没有给出。
  • 您将数据作为查询参数发送,因此您应该访问request.query_params 而不是request.data。我建议您在请求正文中发送敏感数据,然后您就可以通过request.data 访问它

标签: django http post request postman


【解决方案1】:

正如 Ersain 在 cmets 中指出的,您在 Postman 中使用查询参数。

您需要导航到 Postman 中的正文选项卡,选择 raw,然后选择 JSON。然后您可以输入用户名和密码。

【讨论】:

    猜你喜欢
    • 2023-01-21
    • 2019-04-28
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    • 2021-11-04
    • 2022-07-06
    • 1970-01-01
    • 2022-06-16
    相关资源
    最近更新 更多