gpt4 book ai didi

python - request.POST.get() 不返回任何内容

转载 作者:太空宇宙 更新时间:2023-11-03 20:16:11 24 4
gpt4 key购买 nike

我正在使用 Django 运行一个网站。我正在尝试登录,但它没有返回任何内容,并且我没有收到任何错误。它显示 200 状态代码。

这是我的views.py代码:

def user_login(request):
datas= {'log':False}
if request.method == "POST":
usern=request.POST.get('Username')
passw=request.POST.get('password')
response = requests.post(url='http://www.onebookingsystem.com/productionApi/API/Admin/login.php',data={"Username":usern,"password":passw})
json_data = response.json()
if json_data['status'] == 1:
user=authenticate(Username=usern,password=passw)
login(request,user)
range_yearly = 0
range_monthly = 0
respo = requests.get(url='http://www.onebookingsystem.com/productionApi/API/Admin/admin_dashboard.php')
data_dash = json.loads(respo.text)

当我在 POST HTTP 请求中运行时,它显示已成功登录,但是在 GET HTTP 请求中,它显示:Status 0“手机或密码丢失”。//缺少必需的帖子参数。

最佳答案

这可能是因为您使用的请求没有 session 存储。您可以尝试这种(未经测试的)方式:

def user_login(request):
# Create client with session storage to store session cookies
client = requests.Session()

datas= {'log':False}
if request.method == "POST":
usern=request.POST.get('Username')
passw=request.POST.get('password')

# client stores session cookie at login
response = client.post(url='http://www.onebookingsystem.com/productionApi/API/Admin/login.php',data={"Username":usern,"password":passw})

# you can check that with
# print(client.cookies)
json_data = response.json()
if json_data['status'] == 1:
user=authenticate(Username=usern,password=passw)
login(request,user)
range_yearly = 0
range_monthly = 0

# client should be able to access because of its stored session cookie
respo = client.get(url='http://www.onebookingsystem.com/productionApi/API/Admin/admin_dashboard.php')
data_dash = json.loads(respo.text)

More information

关于python - request.POST.get() 不返回任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58430385/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com