0

这是我的登录表单的代码:

<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 表单代码中包含字段的名称,但每次尝试使用数据库中已有的凭据时,我仍然会继续收到错误消息。有任何想法吗?

4

1 回答 1

0

你应该更新你的html表单登录a href到我给的按钮

 <button type="submit" class="btn btn-primary btn-user btn-block">
       Login
 </button>

如果您在视图中打印,您实际上会遇到错误request.POST.get('InputEmail'),您会收到此错误,因为数据没有让您在登录时使用 href,因此它将获得请求而不是实际提交表单

如果您想在数据未通过请求获取默认值时获取默认数据,还请参阅 get 方法字典产生此错误实际上不是获取数据get('key name',default value)

所以需要更新,因为我屈服了a hrefbutton然后让我发生了什么事

于 2020-06-04T06:26:43.230 回答