Login and Redirect
- by xRobot
This is my login views:
def login(request):
redirect_to = request.REQUEST.get("next")
if request.method == 'POST':
formL = LoginForm(data=request.POST)
if formL.is_valid():
if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
redirect_to = "/blogs/"
from django.contrib.auth import login
login(request, formL.get_user())
if request.session.test_cookie_worked():
request.session.delete_test_cookie()
return HttpResponseRedirect(redirect_to)
else:
formL = LoginForm(request)
request.session.set_test_cookie()
return render_to_response('blogs.html', {
'formL': formL, }, context_instance=RequestContext(request))
login = never_cache(login)
When I go, for example, to example.com/myblog/ then I have been redirect to example.com/accounts/login/?next=/myblog/
but when I insert user and psw for login then I have been redirect to /blogs/ and not /myblog/
Why ?