class RegForm(forms.ModelForm):password = forms.CharField(widget=forms.PasswordInput, label='密码', min_length=6) # 重写默认字段re_password = forms.CharField(widget=forms.PasswordInput, label='确认密码', min_length=6) # 新增字段class Meta:model = models.UserProfile # 指定modelfields = '__all__' # ['username','password'] # 指定字段exclude = ['is_active'] #字段为是否可用的用户labels = {'username': '用户名'}widgets = {'username': forms.TextInput(attrs={'class': 'form-control', 'placeholder': '用户名'}),# 'password': forms.PasswordInput(attrs={'class': 'form-control'})}error_messages = {'min_length': '不能少于6位'}def __init__(self, *args, **kwargs):super().__init__(*args, **kwargs)# 自定义操作for field in self.fields.values():# field.widget.attrs['class'] = 'form-control'field.widget.attrs.update({'class': 'form-control'})