[英]Why do I keep getting a multiValueDictKey Error in my Django/Bootstrap project?
Here is the code for my login form:这是我的登录表单的代码:
<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>
and here is the code that the form submission triggers:这是表单提交触发的代码:
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/')
I have tried switch request.POST to request.POST.get, and have the name of the field within the HTML form code, yet I still continue to get an error everytime I try to use credentials that are already in my database.我已尝试将 request.POST 切换为 request.POST.get,并在 HTML 表单代码中使用字段的名称,但每次尝试使用已在我的数据库中的凭据时,我仍然会继续收到错误消息。 Any ideas?
有任何想法吗?
You should update you html form Login a href
to button i give您应该更新您的 html 表单登录我给的按钮
a href
<button type="submit" class="btn btn-primary btn-user btn-block">
Login
</button>
error you actually get in request.POST.get('InputEmail')
if you print in your view you get this error because data not getting you use a href in login so it will get request and not actual submit form错误你实际上得到
request.POST.get('InputEmail')
如果你在你的视图中打印你会得到这个错误,因为数据没有让你在登录时使用 href 所以它会得到请求而不是实际提交表单
and also see get method dictionary produce this error not actually get data if you want get default data when data not pass by request get default value get('key name',default value)
如果您想在数据未通过请求传递时获取默认数据获取默认值
get('key name',default value)
so need to update as i gave in a href
to button
then let me what's happened所以需要更新,因为我在
button
中给出了a href
然后让我知道发生了什么
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.