1. A Problem
This is part of AdminSignupView():
# 🆕 First-time signup
else:
form = AdminSignupForm(request.POST)
if not form.is_valid():
print("form.is_valid() is not True")
return render(request, "accounts/signup.html", {"form": form})
print("Creating new user") # debug
user = form.save(commit=False)
user.is_active = False
user.has_paid = False
user.signup_completed = False
user.save()
With this, if form.is_valid() is not true, the signup form is displayed silently again. I tried to signup with a password of 6 letters and numbers, which seems invalid. I would like to show an error message on the signup form display. How can I do it?
Django already stores the validation errors inside the form when form.is_valid() fails. You only need to
display those errors in the template. You do not need extra logic in the view.
Your view is already correct:
Because you pass the same form object back to the template, it contains:
-
field errors
-
password validation errors
-
non-field errors
The only missing step is showing them in the template.
1️⃣ The simplest way (recommended)
In your template:
accounts/templates/accounts/signup.html
Add this near the top of the form:
Django will automatically show errors like:
2️⃣ Better display (more professional)
Instead of form.as_p, render fields manually so errors appear under each field.
Example:
{% csrf_token %}
<div>
Then the error will appear like:
• This password is too short. It must contain at least 8 characters.
3️⃣ Very useful for debugging
You can also temporarily print all errors:
Example output:
4️⃣ Why Django already knows the password is invalid
Your form probably inherits from:
That automatically applies validators defined in:
in settings.py.
Example:
So your 6-character password failed the MinimumLengthValidator.
5️⃣ Small improvement to your view
You can simplify:
return render(request, "accounts/signup.html", {"form": form})
to:
Or even simpler.
🎯 Final Result
When the user submits a weak password like:
The page will reload and show:
without silently failing.
✅ If you want, I can also show you a very clean SaaS-style signup form template (similar to Stripe/GitHub style) that displays Django errors beautifully. It would fit your commercial client portal very well.
