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


so using django-registration app implement user registration page site. used django's backends.simple views allows users login after registration. question how redirect them other app's page located in same directory project.

here main urls.py looks like:

from django.conf.urls import patterns, include, url  # uncomment next 2 lines enable admin: # django.contrib import admin # admin.autodiscover()  urlpatterns = patterns('',      url(r'^accounts/', include('registration.backends.simple.urls')),     url(r'^upload/', include('mysite.fileupload.urls')),     # examples:     # url(r'^$', 'mysite.views.home', name='home'),     # url(r'^mysite/', include('mysite.foo.urls')),      # uncomment admin/doc line below enable admin documentation:     # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),      # uncomment next line enable admin:     # url(r'^admin/', include(admin.site.urls)), )  import os urlpatterns += patterns('',         (r'^media/(.*)$', 'django.views.static.serve', {'document_root': os.path.join(os.path.abspath(os.path.dirname(__file__)), 'media')}), ) 

fileupload name of other app have in project directory mysite.

this backends.simple.urls looks like:

""" urlconf registration , activation, using django-registration's one-step backend.  if default behavior of these views acceptable you, use line in root urlconf set default urls registration::      (r'^accounts/', include('registration.backends.simple.urls')),  automatically set views in ``django.contrib.auth`` @ sensible default locations.  if you'd customize registration behavior, feel free set own url patterns these views instead.  """   django.conf.urls import include django.conf.urls import patterns django.conf.urls import url django.views.generic.base import templateview  registration.backends.simple.views import registrationview   urlpatterns = patterns('',                        url(r'^register/$',                            registrationview.as_view(),                            name='registration_register'),                        url(r'^register/closed/$',                            templateview.as_view(template_name='registration/registration_closed.html'),                            name='registration_disallowed'),                        (r'', include('registration.auth_urls')),                        ) 

and here backends.simple.views:

from django.conf import settings django.contrib.auth import authenticate django.contrib.auth import login django.contrib.auth.models import user  registration import signals registration.views import registrationview baseregistrationview   class registrationview(baseregistrationview):     """     registration backend implements simplest possible     workflow: user supplies username, email address , password     (the bare minimum useful account), , signed     , logged in).      """     def register(self, request, **cleaned_data):         username, email, password = cleaned_data['username'], cleaned_data['email'], cleaned_data['password1']         user.objects.create_user(username, email, password)          new_user = authenticate(username=username, password=password)         login(request, new_user)         signals.user_registered.send(sender=self.__class__,                                      user=new_user,                                      request=request)         return new_user      def registration_allowed(self, request):         """         indicate whether account registration permitted,         based on value of setting ``registration_open``.         determined follows:          * if ``registration_open`` not specified in settings, or           set ``true``, registration permitted.          * if ``registration_open`` both specified , set           ``false``, registration not permitted.          """         return getattr(settings, 'registration_open', true)      def get_success_url(self, request, user):         return (user.get_absolute_url(), (), {}) 

i tried changing get_success_url function return url want /upload/new still redirected me users/insert username page , gave error. how redirect user upload/new page other app resides after registration?

don't change code in registration module. instead, subclass registrationview, , override get_success_url method return url want.

from registration.backends.simple.views import registrationview  class myregistrationview(registrationview):     def get_success_url(self, request, user):         return "/upload/new" 

then include custom registration view in main urls.py, instead of including simple backend urls.

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

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -