After succesfully registering, the user is redirected to the template 'registration_complete.html'.
Is there any way of changing this behaviour to redirecting the user to the registration page and displaying a message?
I thought of doing something like this in registration_complete.html:
{% include 'registration/registration_form.html' with message='Your account has been created. Please check your email for activation instructions' %}
But the form
variable that I use in the template is not available in this view, so the registration form is not shown. Furthermore, I don't know if this is the best way of doing this.
EDIT:
url(r'^register/$', 'registration.views.register',
{
'backend': 'trabam.apps.accounts.regbackend.Backend',
'form_class' : UserRegistrationForm,
'success_url': '/accounts/register'
},
name='registration_register'
),
How can I set a message in my template after registration is completed?
You can specify the success_url which will redirect the user to that url on successful registration.
In order to display a message a simple approach would be add a get parameter in the success_url also, but you have to modify the view to get it from request.GET and place in your request context.
in urls.py:
url(r'^register/$', 'registration.views.register',
{
'backend': 'trabam.apps.accounts.regbackend.Backend',
'form_class' : UserRegistrationForm,
'success_url': '/accounts/register/?on_success=true'
},
name='registration_register'
),
in view:
on_success = request.GET.get('on_success', None)
context.update({'on_success': on_success})
in template:
{% if on_success %}
<p>You are successfully registered</p>
{% endif %}