How to redirect users to a specific url after registration in django registration?

Deadly 提交于 2019-12-03 06:54:18

Don't change the code in the registration module. Instead, subclass the RegistrationView, and override the get_success_url method to return the url you want.

from registration.backends.simple.views import RegistrationView

class MyRegistrationView(RegistrationView):
    def get_success_url(self, request, user):
        return "/upload/new"

Then include your custom registration view in your main urls.py, instead of including the simple backend urls.

urlpatterns = [
    # your custom registration view
    url(r'^register/$', MyRegistrationView.as_view(), name='registration_register'),
    # the rest of the views from the simple backend
    url(r'^register/closed/$', TemplateView.as_view(template_name='registration/registration_closed.html'),
                          name='registration_disallowed'),
    url(r'', include('registration.auth_urls')),
]

If you wish, you can modify the following file /usr/local/lib/python2.7/dist-packages/registration/backends/simple/urls.py, changing the path, for example:

Before modifying:

success_url = getattr (settings, 'SIMPLE_BACKEND_REDIRECT_URL', '/'),

After modifying:

success_url = getattr (settings, 'SIMPLE_BACKEND_REDIRECT_URL', '/upload/new'),

Regards.

Diego

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!