Wher is the form action? If you don't provide the form action then how can
it recognize which views should be called?
Set the action here: <form action="{ % url 'register' %}" method = "POST">

Like this.

On Sat, Aug 24, 2019 at 10:34 PM Kean <[email protected]> wrote:

> Hi,
>
> New to Django.
> I've created a user registration form, the issue is it does not run
> validations or report errors with the data entered. It simply routes to the
> redirect url.
> Please can I ensure the user sees the correct error in a post case scenari
> for both a django form, and customsied django form.
>
> forms.py
>
> class UserRegisterForm(UserCreationForm):
>     email = forms.EmailField()
>
>     class Meta:
>         model = User
>         fields = 'username', 'email', 'password1', 'password2'
>
> Views.py
>
> def register(request):
>     if request.method == 'POST':
>         form = UserRegisterForm(request.POST)
>         if form.is_valid():
>             form.save()
>             username = form.cleaned_data.get('username')
>             messages.success(request, f'Account created for {username}')
>         return HttpResponseRedirect('cprofile')
>     else:
>         form = UserRegisterForm()
>     context = {'form': form}
>     return render(request, "register.html", context,)
>
> template.html
>
> <head>
> <title>Registration</title>
> </head>
> <body>
> <br>
> <div class = "container">
> <form method = "POST">
> {% csrf_token %}
> <fieldset class="form">
> <legend class="border-bottom mb-2">Register</legend>
> {{ form|crispy }}
> {% if messages %}
> {% for messages in messages %}
> <div class="alert alert{{ message.tag }}">
> {{ messages }}
> </div>
> {% endfor %}
> {% endif %}
> </fieldset>
> <br>
> <div class = "form">
> <button class ="btn btn-outline-info" type="submit">Register</button>
>
> Any help would be much appreciated
>
> 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/5a003506-de8d-4587-863d-3fc26e4c45c1%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5a003506-de8d-4587-863d-3fc26e4c45c1%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CACNsr2-PMs1qvhjPrsbk9Rjgku_9dvL%2B9PAbO51Ndc9mhOnOQQ%40mail.gmail.com.

Reply via email to