【问题标题】:form is not valid to django why [closed]表单对 django 无效,为什么 [关闭]
【发布时间】:2019-08-29 10:03:58
【问题描述】:

型号:

    class authentifier(models.Model):
    matricule =models.CharField(max_length=254, blank=True, null=True)
    password = models.CharField(max_length=254, blank=True, null=True)
    nom =models.CharField(max_length=254, blank=True, null=True)
    prenom=models.CharField(max_length=254, blank=True, null=True)
    statut = models.CharField(max_length=254, blank=True, null=True)

验证码forms.py:

     from django import forms
     class UserLoginForm(forms.Form):
     print(666)
     matricule =  forms.CharField(required=True , widget=forms.TextInput)
     password = forms.CharField(required=True , widget= forms.PasswordInput)

模板html:

   <!DOCTYPE html>
   <html lang="en">
   <head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width , initial- 
     scales=1.0">
       <meta http-equiv="X-UA-Compatible" content="ie=edge">

       </head>
      <body>
           <form>
        <form method="POST">
    {%  csrf_token %}
   <tr><th><label for="id_matricule">Matricule:</label></th><td><input 
  type="text" name="matricule"  id="Matricule"></td></tr>
    <tr><th><label for="id_password">Password:</label></th><td><input 
      type="password" name="password"  id="password"></td></tr>
        <input type="submit" value="Se Connecter">

          </form>


            </body>


                  </html>

我发现 form.is_valid() = false - 但我不知道如何得到原因 WHY...

我需要使用矩阵和密码进行身份验证

【问题讨论】:

  • 查看代码在哪里?还有为什么你的 HTML 中有 2 个
    标签?还有为什么不使用 Django 提供的表单渲染工具(例如{{ form.as_p }})而不是手动输入所有字段。

标签: python django authentication


【解决方案1】:

你应该在模板中添加{{ form.errors }},然后Django会告诉你为什么表单无效。

【讨论】:

    猜你喜欢
    • 2017-12-16
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-16
    • 2016-10-03
    相关资源
    最近更新 更多