Django-Registration Activation redirect with django.contrib.messages

后端 未结 2 1304
离开以前
离开以前 2021-01-14 19:38

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 messag

2条回答
  •  忘掉有多难
    2021-01-14 19:48

    ilvar's response is probably a better way to do it, but I also managed to get it working by wrapping a view around django-registration view.

    In urls.py I now point to my new view

    url(r'^accounts/activate/(?P\w+)/$',
            Custom_Activation_View.as_view(),
            {'backend': 'registration.backends.default.DefaultBackend'},
            name='registration_activate'),
    

    and in my views.py file:

        class Custom_Activation_View(TemplateView):
            template_name='home.html'
    
            def get(self, request, backend, success_url=None, extra_context=None, **kwargs):
                messages.success(self.request, 'Activation complete, please login below')
    
                return activate(self.request, backend, template_name=self.template_name, success_url='/', extra_context=None, **kwargs)
    

提交回复
热议问题