Django注册激活重定向与django.contrib.messages [英] Django-Registration Activation redirect with django.contrib.messages
问题描述
我正在尝试设置我的django注册激活工作流程,以便当用户点击激活链接时,使用django消息框架 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
现在,我已经设法使用 success_url将用户发回主页/ code>参数:
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',
),
其中'/'
是家庭登录视图。我需要在路上的某个地方设置成功讯息,或许使用 extra_context
字段?
where '/'
is the home login view. I need to set the success message somewhere along the way...perhaps using the extra_context
field?
推荐答案
Django注册是使用信号挂钩一些点。在你的情况下,应该是这样的:
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)
这篇关于Django注册激活重定向与django.contrib.messages的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!