新建一个Form类。
from django import forms
class LoginForm(forms.Form):
UserName = forms.CharField(max_length=6)
PassWord = forms.CharField(widget=forms.PasswordInput)
#PassWord = forms.CharField(widget=forms.PasswordInput,required = False)
{% if form.errors %}
<style>
.errorlist{
color:red;
background-color:#ccc;
}
</style>
{% endif %}
<form method=‘post‘ action=‘/Login‘> {% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type=‘submit‘ value=‘Submit‘>
</form>
时间: 2024-10-06 14:05:31