让我修改这个问题
我有一个自己的登录视图,如下所示,并且正在实现@login_required
装饰器。
def do_login(request):
form = LoginForm()# create an instance of a login form
logged_in =request.user.is_authenticated() # get login status
if logged_in:
message='You are logged in '
return render_to_response('login.html',locals())# return
if request.method == 'POST':
usr=request.POST['username'] #get username
passwrd=request.POST['password']# get password
form=LoginForm(request.POST) # create instance of loginform
user=authenticate(username=usr,password=passwrd)# authenticate user
if user is not None:
if user.is_active:
login(request,user) #log user in
return HttpResponseRedirect("/login_success/")
else:
pass
else:
return render_to_response('login.html',locals())
else:
return render_to_response('login.html',locals())
这很有效,因为每当我尝试访问一个 url(例如更改密码)时,都会被带到登录页面以首先登录。在登录页面时,地址栏中显示的 url 是http://myapp.com/login/?next=/change_password/
现在,当我登录时被带到http://myapp.com/login/login_success/
而不是http://myapp.com/login/change_password/
. 登录后,我希望自动重定向到在http://myapp.com/login/change_password/
被要求登录之前尝试访问的目标。请问我该如何解决