Pass success_url to activate

The docs say:

 ``success_url``
    The name of a URL pattern to redirect to on successful
    acivation. This is optional; if not specified, this will be
    obtained by calling the backend's
    ``post_activation_redirect()`` method.

How can i do this?

+3
source share
1 answer

You can do this in urls.py, for example:

url(r'^account/activate/(?P<activation_key>\w+)/$', 'registration.views.activate', {'success_url': 'registration_activation_complete'}, name='registration_activate'),
url(r'^account/activate/success/$', direct_to_template, {'template': 'registration/activation_complete.html', name='registration_activation_complete'),

Another approach is to create your own backend (which is easier than it sounds), inheriting from the default backend:

from registration.backends.default import DefaultBackend

class MyRegistrationBackend(DefaultBackend):
    def post_activation_redirect(self, request, user):
        # return your URL here

The simplest solution is to simply name your URL pattern that django-registration should use registration_activation_complete. See Naming URL patterns in Django docs.

+7
source

Source: https://habr.com/ru/post/1766861/


All Articles