邮递员POST请求在django中返回None

时间:2021-04-28 12:51:30

标签: django http post request postman

我正在尝试使用邮递员向 django 服务器中的 API 发送 POST 请求。 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)


这是联合图像中的邮递员请求enter image description here

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

1 个答案:

答案 0 :(得分:1)

正如 Ersain 在评论中指出的那样,您正在 Postman 中使用查询参数。

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

How to add data to the body of a request using postman

相关问题