【发布时间】:2020-08-23 23:24:24
【问题描述】:
我是 Django 新手,今天构建了一个简单的测试。
def login_web(request):
request.encoding = "utf-8"
print("POST type ", request.method)
print("body : ", request.body)
print("POST : ", request.POST)
print("GET : ", request.GET)
username = request.POST.get("username")
password = request.POST.get("password")
print(username)
print(password)
user = auth.authenticate(username=username, password=password)
if user is not None and user.is_active:
print("YR1")
auth.login(request, user)
return JsonResponse({"foo": "bar1"})
else:
print("IM2")
return JsonResponse({"foo": "bar2"})
我使用 Postman 向它发送 post 请求。
但结果很混乱。
POST type POST
body : b''
POST : <QueryDict: {}>
GET : <QueryDict: {'username': ['chivier'], 'password': ['123456']}>
None
None
IM2
我用request.method查了一下,确定我发送了一个POST请求。
我应该让它们出现在 request.POST 中,但为什么它们出现在 request.GET 中。
【问题讨论】:
标签: django python-3.x postman