0Pricing
Django Academy · Aula

Registro com UserCreationForm

Permita que os usuários se cadastrem com segurança

Registro com UserCreationForm é uma aula grátis de Django Academy no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Django Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Django Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Let People Sign Up

Login assumes accounts already exist. To let visitors create their own, you need a registration view backed by a sign-up form. ✍️

Meet UserCreationForm

Django gives you UserCreationForm, a ready form with username and two password fields that creates a User on save.

from django.contrib.auth.forms import UserCreationForm

Built-In Password Checks

The form confirms the two passwords match and runs Django's strength validators, so weak or mismatched passwords are rejected automatically.

Show the Form on GET

On a GET request, create an empty form and render it. This is the blank sign-up page the visitor first sees.

form = UserCreationForm()
return render(request, "signup.html", {"form": form})

Bind Data on POST

On a POST, build the form with request.POST so it holds the submitted values, ready to validate.

form = UserCreationForm(request.POST)

Validate Then Save

Call is_valid(); if it passes, form.save() inserts the new user with a properly hashed password. One line creates the account.

if form.is_valid():
    user = form.save()

Log Them In Right Away

A smooth flow signs the user in immediately after sign-up. Call login() with the saved user so they skip a second step.

user = form.save()
login(request, user)

Render the Errors

When validation fails, just render the same form again. It carries error messages that tell the user exactly what to fix.

The Sign-Up Template

Your template wraps the form in a POST and adds csrf_token. Output the fields and a submit button to finish the page.

Extending the Form

Need an email field? Subclass UserCreationForm and add it. The built-in form keeps things minimal until you ask for more.

Redirect After Success

Finish by sending the new user somewhere useful with a redirect, like their dashboard, instead of re-rendering the form.

return redirect("dashboard")

Quick Check

What does UserCreationForm verify about the password automatically?

Recap: Registration

You used UserCreationForm to validate sign-ups, saved the new user with a hashed password, and logged them in right away. ✅

Perguntas Frequentes

A aula “Registro com UserCreationForm” é grátis?

Sim — o texto completo de “Registro com UserCreationForm” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Django Academy, atualize para CoddyKit PRO. O curso de Django Academy inclui 4 aulas no total.

O que vou aprender em “Registro com UserCreationForm”?

Permita que os usuários se cadastrem com segurança Você pratica Django Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Django Academy?

Nenhuma experiência prévia é necessária. Django Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.

Quanto tempo leva a aula “Registro com UserCreationForm”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Django Academy?

Sim. Cada aula de Django Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. O modelo User e authenticate()
  2. login, logout e visualizações de autenticação
  3. Registro com UserCreationForm
  4. login_required e proteção de visualizações
← Voltar para Django Academy