Registro con UserCreationForm
Permita que los usuarios se registren de forma segura
Registro con UserCreationForm es una lección gratuita de Django Academy en CoddyKit. Esta es la lección 3 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Django Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Django Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en 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 UserCreationFormBuilt-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. ✅
Preguntas frecuentes
¿La lección «Registro con UserCreationForm» es gratis?
Sí — el texto completo de «Registro con UserCreationForm» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Django Academy, actualiza a CoddyKit PRO. El curso de Django Academy incluye 4 lecciones en total.
¿Qué aprenderé en «Registro con UserCreationForm»?
Permita que los usuarios se registren de forma segura Practicas Django Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Django Academy?
No se requiere experiencia previa. Django Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 3 de 4.
¿Cuánto tiempo toma la lección «Registro con UserCreationForm»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Django Academy?
Sí. Cada lección de Django Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- El modelo User y authenticate()
- login, logout y Auth Views
- Registro con UserCreationForm
- login_required y protección de vistas