以下是我的登录表单的代码:
<form class="user" action="/returningAgent/" method="post" >
<div class="form-group">
<input type="email" class="form-control form-control-user" id= "InputEmail" name="InputEmail" aria-describedby="emailHelp" placeholder="Enter Email Address...">
</div>
<div class="form-group">
<input type="password" class="form-control form-control-user" id="InputPassword" name="InputPassword" placeholder="Password">
</div>
<div class="form-group">
<div class="custom-control custom-checkbox small">
<input type="checkbox" class="custom-control-input" id="customCheck">
<label class="custom-control-label" for="customCheck">Remember Me</label>
</div>
</div>
<a href="/returningAgent/" class="btn btn-primary btn-user btn-block">
Login
</a>
<hr>
<a href="/returningAgent/" class="btn btn-google btn-user btn-block">
<i class="fab fa-google fa-fw"></i> Login with Google
</a>
<a href="/returningAgent/" class="btn btn-facebook btn-user btn-block">
<i class="fab fa-facebook-f fa-fw"></i> Login with Facebook
</a>
</form>
以下是表单提交触发的代码:
def returningAgent(request):
#try:
x = Agent.objects.get(bizEmail = request.POST["InputEmail"], password = request.POST["InputPassword"])
diction = {
'f' : x.firstName,
'l' : x.lastName,
'e' : x.bizEmail
}
return render(request, 'index.html', diction)
#except:
#return HttpResponseRedirect('/404/')
我已尝试将request.POST切换到request.POST.get,并在HTML表单代码中包含该字段的名称,但每次尝试使用数据库中已有的凭据时,仍会继续出现错误。有什么想法吗
您应该将html表单Login
a href
更新为我给出的按钮您在
request.POST.get('InputEmail')
中实际收到的错误如果您在视图中打印,您会收到此错误,因为您在登录时使用了href,因此它将收到请求,而不是实际的提交表单另请参阅get method dictionary生成此错误not Actual get data如果您希望在数据未通过请求时获取默认数据获取默认值
get('key name',default value)
所以需要更新我在
a href
到button
中给出的内容,然后告诉我发生了什么相关问题 更多 >
编程相关推荐