模型:
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-但我不知道为什么要弄清原因...
我需要使用矩阵和密码进行身份验证
答案 0 :(得分:2)
您应该在模板中添加{{ form.errors }}
,然后Django会准确告诉您表单无效的原因。