I am using Django 1.7 with Python 3.4 . I have a scenario where I want users to be redirected to another view, as defined in the next GET parameter, after logging in. But with my current setup, they are always redirected to the home page. I was hoping there was a way to do this in the get_success_url class.
Below is my code
Next parameter in url
http://localhost:8000/login/?next=/ads/new
views.py
from django.views.generic.edit import FormView class LoginView(FormView): template_name = 'users/login.html' form_class = LoginForm def get_success_url(self): return reverse('home') def form_valid(self, form): form.user.backend = 'django.contrib.auth.backends.ModelBackend' login(self.request, form.user) messages.info(self.request, 'Login successful') return super(LoginView, self).form_valid(form)
urls.py
url(r'^login/', LoginView.as_view(), name='login'), url(r'^new$', 'apps.adverts.views.add_new_advert', name='new_advert'),
With the setting above, how do I redirect to the next URL if it is defined other than the main page?
source share