gpt4 book ai didi

python - 登录时出现407错误如何解决?

转载 作者:行者123 更新时间:2023-12-01 07:03:08 27 4
gpt4 key购买 nike

我尝试通过打印来检查问题的原因在哪里。它显示 user_id 和密码在那里,但之后无法继续。

def login_request(request):
if request.method == 'POST':
user_id = request.POST['user_id']
password = request.POST['password']
user = authenticate(user_id=user_id, password=password)
if user is not None:
login(request, user)
return redirect("/index")
else:
messages.info(request, 'Invalid Credentials')
return redirect('login_request')
else:
return render(request, 'login.html')

url.py 路径('login_request/',views.login_request,name='login_request'),

最佳答案

您需要使用用户名密码而不是user_id来验证用户

if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(request,username=username, password=password)
if user is not None:
login(request, user)
return redirect("/index")
else:
messages.info(request, 'Invalid Credentials')
return redirect('login_request')
else:
return render(request, 'login.html')

关于python - 登录时出现407错误如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58553391/

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