dimanche 12 septembre 2021

How can I insert a checkbox in my django Sign Up form?

This is my forms.py file

class SignUpForm(UserCreationForm):
email = forms.EmailField(widget= forms.EmailInput(attrs={'class':'form-control'}))
first_name = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'class':'form-control'}))
last_name = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'class':'form-control'}))

class Meta:
    model = User 
    fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2')

def __init__(self, *args, **kwargs):
    super(SignUpForm, self).__init__(*args, **kwargs)

    self.fields['username'].widget.attrs['class'] = 'form-control'
    self.fields['password1'].widget.attrs['class'] = 'form-control'
    self.fields['password2'].widget.attrs['class'] = 'form-control'

I want to add a boolean checkbox on my signup form, but not quite getting there.

Any help would be appreciated.




Aucun commentaire:

Enregistrer un commentaire