2π
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 %}
0π
It seems from your urls.py that you are sending the success_url
as the register
view itself. You canβt do this because it would require you to change register
view if you want to send a message
in the context after successful registration.
So, you need to write an extra view. Suppose this file is accounts/views.py
.
from registration.forms import RegistrationForm
def registration_complete(request):
.....
form = RegistrationForm()
.....
message = "You are successfully registered"
return render_to_response("registration/registration_form.html", {'form': form, 'message': message})
The template registration/registration_form.html
is the same that will be used by django-registration
.
accounts/urls.py
url(r'^registration_complete/', 'accounts.views.registration_complete', name='accounts_registration_complete'),
Your urls.py
urlpatterns = patterns('',
(r'^registration/register/$', 'registration.register', {'backend': 'registration.backends.default.DefaultBackend', 'success_url': 'accounts_registration_complete'}),
(r'^registration/', include('registration.urls')),)
registration/registration_form.html
{% if message %}
{{message}}
{% endif %}
.......
{{form.as_p}}
So, only after successful registration, your success_url
will be used which will call the view registration_complete
defined by you. This view will send message
in the context which the registration template can use.