In my forms.py file I reconfigured the class UserForm's __init__
function to include a css class. Unfortunately doing this only allowed me to add a class to the <input>
and not the <label>
. How can I add a class to the label as well?
Here is my forms.py file:
class UserForm(forms.ModelForm):
# password = forms.CharField(widget=forms.PasswordInput())
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__(*args, **kwargs)
self.fields['email'].widget.attrs = {
'class': 'form-control'
}
class Meta:
model = User
fields = ('email',)
def clean_email(self):
email = self.cleaned_data['email']
if not email:
raise forms.ValidationError(u'Please enter an email address.')
if User.objects.exclude(pk=self.instance.pk).filter(email=email).exists():
raise forms.ValidationError(u'Email "%s" is already in use.' % email)
return email
Thanks!