Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

545
Views
I can't create a form with password1 password2 in Django

error:Unknown field(s) (password1, password2) specified for User

I have no idea why it doesn't work as documentation says

Documentation:

class UserCreationForm¶
A ModelForm for creating a new user.

It has three fields: username (from the user model), password1, and password2. 
It verifies that password1 and password2 match, validates the password using validate_password(), 
and sets the user’s password using set_password().

My forms.py


class CreateUserForm(UserCreationForm):
   class Meta:
       model = User
       fields = ['username', 'email', 'password1', 'password2']

my views.py



class CreateUserView(CreateView):
   model = User
   form = CreateUserForm
   template_name = 'registration/register.html'
   fields = ['username', 'email', 'password1', 'password2 ]


class UserLoginView(LoginView):
   next_page = "home.html"
']

urls.py


urlpatterns = [
    path('register/', CreateUserView.as_view(), name='register'),


]
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

password1 and password2 are not fields of the User. You should remove these:

class CreateUserForm(UserCreationForm):
   class Meta(UserCreationForm.Meta):
       model = User
       fields = ['username', 'email']

but with this, it makes not much sense to inherit the form anyway.

Furthermore you specify the form class with form_class [Django-doc], not form, so:

class CreateUserView(CreateView):
   model = User
   form_class = CreateUserForm
   template_name = 'registration/register.html'
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!