简体   繁体   English

为什么我的 Django/Bootstrap 项目中不断出现 multiValueDictKey 错误?

[英]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.

相关问题 为什么我的Django项目中总是出现此“名称未定义模型”错误? - Why do I keep getting this “name 'Model' is not defined” error in my Django project? 为什么我在 Django 3.2 中不断收到 NoReverse 错误 - Why do I keep getting a NoReverse Error in Django 3.2 为什么我不断收到此属性错误? - Why do I keep getting this Attribute Error? 为什么我不断收到此错误消息? - Why do i keep getting this error message? 所以我在学校项目的 Tkinter 代码中不断收到这个名称错误,我不太明白为什么 - so i keep getting this name error in my Tkinter code for a school project and i dont quite understand why 我的 pygame 项目不断出现属性错误,我不明白为什么 - Keep getting an attribute error on my pygame project and I don't understand why 为什么我在尝试运行代码时不断收到导入错误消息? - Why do I keep getting a error message for import when I try to run my code? 为什么我的代码中总是出现列表索引超出范围错误? - Why do I keep getting a list index out of range error in my code? 为什么我在第五行不断收到错误的输入错误? 我的变量好吗? function的声明? - why do I keep getting a bad input error on line five? are my variables alright? the declaration of function? 为什么我一直在使用我的函数获取UnboundLocalError? - Why do I keep getting a UnboundLocalError with my function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM