I have a custom login url/view/template. I use the @login_required decorator for a page (let 's call it my_page) that requires login. Attempting to access
my_site.com/my_page
correctly calls
my_site.com/login/?next=/my_page/
BUT my view is unable to parse out the value of ?next=/my_page/my and instead always redirects to my default which is /qa/ in my view:
def login_with_email(request):
error = ''
if request.method == 'POST':
if not request.POST.get('email', ''):
error = 'Please enter your email and password'
if not request.POST.get('password', ''):
error = 'Please enter your email and password'
if not error:
email = request.POST['email']
password = request.POST['password']
try:
user = User.objects.get(email=email)
user = authenticate(username=user.username, password=password)
if user is not None:
if user.is_active:
login(request, user)
# ***
next_page = request.GET.get('next', '/qa/')
response = HttpResponseRedirect(next_page)
# ***
response.set_cookie('login_email', email, max_age=14*24*60*60)
return response
except User.DoesNotExist:
error = 'Invalid email and password combination'
Urls.py:
url(r'^login/$', views.login_with_email),