Hi,
New to Django.
I've created a registration form which inherits from a User form.
The issue is none of the validators are working. e.g reporting to user
password miss-match, or any other error if user enters data incorrect to
validation.
The form simply validates with errors and redirect user to to their user
page (as defined,).
Please can anyone help or advise, as I though the validators were an
inherent part of the django forms?
forms.py
class CRegisterForm(UserCreationForm):
email = forms.EmailField(max_length=30, required=True)
class Meta:
model = User
fields = ['username', 'email', 'password1', 'password2']
views.py
def cregister(request):
if request.method == "POST":
form = CRegisterForm(request.POST)
if form.is_valid():
data = form.cleaned_data
form.save()
return redirect('cpage')
else:
form = CRegisterForm()
return render(request, 'cregister.html', {'form': form})
urls.py
path('login/customer/', views.cpage, name='cpage'),
html
{% load crispy_forms_tags %}
<!DOCTYPE html>
<html>
<head>
<title>Customer</title>
</head>
<br>
<body>
<div>
<div class = "container" >
<form method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend class="border-bottom mb-3">Customer Login</legend>
{{ form|crispy }}
</fieldset>
<div class="form-group">
<button class="btn btn-outline-info" type="submit">Login</button>
</div>
{% if messages %}
{% for messages in messages %}
<div class="alert alert-{{ message.tags }}">
{{ message }}
</div>
{% endfor %}
{% endif %}
</form>
<div class="border-top pt-3">
<small class = "text-muted">
Need a customer account <a class="ml-2" href="cregister">Customer
register</a>
</small>
</div>
</div>
</body>
</html>
Best,
K
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/a4739118-05b9-4706-b1cb-08062cc6f93d%40googlegroups.com.