Search code examples
djangomessagedjango-registrationactivation

Django-Registration Activation redirect with django.contrib.messages


I'm trying to set up my django-registration activation workflow so that when the user hits the activation link it redirects them to the login page with a nice little message using the django messages framework django.contrib.messages

Right now, I've managed to send the user back to the homepage using the success_url parameter:

 url(r'activate/(?P<activation_key>\w+)/$',
    activate,
    {'backend': 'registration.backends.default.DefaultBackend', 'success_url':'/'},
        name='registration_activate',
    ),

where '/' is the home login view. I need to set the success message somewhere along the way...perhaps using the extra_context field?


Solution

  • Django-registration is using signals to hook on some points. In your case it should be something like:

    from registration import signals
    def register_handler(request, **kwargs):
        messages.success(request, 'Thank you!')
    signals.user_registered.connect(register_handler)