> `views.py` has this:
> def login_register(request, template="pages/login_register.html"):
> '''
> Display registration and login forms
> '''
> registration_form= RegisterForm()
> return render(request, template, {"registration_form": registration_form
> })
>
>
>
>
> def register(request):
> '''
> Process user registration
> '''
> if request.method=="POST":
> form= RegisterForm(request.POST)
> print form.is_valid()
> if form.is_valid():
> form.save()
> email= form.cleaned_data.get("email")
> raw_password= form.cleaned_data.get("password1")
> user= authenticate(username=email, password=raw_password)
> login(request, user)
> return redirect(home_slug())
>
> else:
>
-> Here you should redirect back to to login_register as fallback option,
for this code, try removing this "else"
> return redirect(reverse("login_register"))
>
>
>
When I fill out registration with an email that already exists, I get this
> error: `ValueError: The view theme.views.register didn't return an
> HttpResponse object. It returned None instead.`. That's because when
> `form.is_valid()` is False, there is no return value. What do I need to
> return so that the message on the Registration form states the email
> already exists?
>
>
When you process the form in a different view, when you redirect you will
loose the form content, a better approach is to process it in the same
view, this way the errors will be shown "automatically":
https://stackoverflow.com/questions/14647723/django-forms-if-not-valid-show-form-with-error-message
Or handle the errors by yourself as shown here:
https://docs.djangoproject.com/en/1.11/intro/tutorial04/
:)
--
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CA%2BFDnhKEjjz3PX-55ad%2BtiiFt2fF4Lx0cz10n_Rg4aL_xB_ezA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.