Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

546
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda