1

I want to modify the weight of the fields in UserCreationForm. How is that possible?

class SignUpForm(UserCreationForm):
    username = forms.CharField( widget=forms.TextInput(attrs={
        "class": "input",
        "type": "text",
        "placeholder": "Username",
    }) )

    email = forms.CharField(widget=forms.TextInput(attrs={
        "class": "input",
        "type": "email",
        "placeholder": "Email"
    }))

    password1 = forms.CharField(widget=forms.TextInput(attrs={
        "class": "input",
        "type": "password",
        "placeholder": "Password"
    }))

    password2 = forms.CharField(widget=forms.TextInput(attrs={
        "class": "input",
        "type": "password",
        "placeholder": "Password"
    }))


    class Meta:
        model= User
        fields = [
            "username", "email", "password1", "password2"
        ]

I want to modify the size of the fields: Username, Email, Password 1, and Password 2

More precisely, I want the fields longer. I would appreciate any help.

Nallath
  • 2,100
  • 20
  • 37
replaalpi
  • 29
  • 5
  • The [django documentation](https://docs.djangoproject.com/en/4.1/ref/forms/widgets/#django.forms.Widget.attrs) explains how to set `size`. – J_H Dec 13 '22 at 15:30
  • Does this answer your question? [Change the width of form elements created with ModelForm in Django](https://stackoverflow.com/questions/110378/change-the-width-of-form-elements-created-with-modelform-in-django) – J_H Dec 13 '22 at 16:42
  • See also the `attrs={'size':'20'}` setting in https://stackoverflow.com/questions/910169/resize-fields-in-django-admin/72847861#72847861 – J_H Dec 13 '22 at 16:51

0 Answers0