Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

django的request.POST和request.body全部都是空

我在django中写了一个登录请求打算使用他做前端的vue现在还没有去做token的保持功能,我使用postman进行post请求时,写了username和password但是后端当我打印这个request.POST和request.body时这两个均为空这个是为什么

def log_in(request):
    print(request.body)
    response = {}
    if request.method == "POST":
        username = request.POST.get("username")
        password = request.POST.get("password")
        print(username, password)
        user = auth.authenticate(username=username, password=password)  # 验证用户名和密码
 if user:
            # 如果认证成功,就让登录,这个login里面包括了session操作和cookie
 auth.login(request, user)
            return JsonResponse('登录成功了', safe=False)
        else:
            s = "用户名和密码输入错误"
 print('hahahaha')
            return JsonResponse('username', safe=False)
    return JsonResponse('登录失败了', safe=False)

image.png
image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

看你的postman,参数写的位置不对
params是填充在url上
请求体的参数是body


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...