Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

548
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda