我有一个自定义表单在我的Django应用程序中注册用户。此自定义表单继承自django.contrib.auth.forms.UserCreationForm类。在我的自定义表单类中,我想向字段添加自定义HTML属性。当我这样做时,属性只添加到某些字段而不是其他字段。在我的例子中,自定义属性“class”仅添加到“email”字段而不是“username”字段。如果我在这里做错了并帮我解决问题,请告诉我。
我的自定义表单的代码在这里:
class EmployeeRegistrationForm(UserCreationForm):
class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2')
widgets = {'username':forms.TextInput(attrs={'class':'form-control','placeholder':'username'}),
'email':forms.TextInput(attrs={'class':'form-control','placeholder':'email'})}