视图.py
def loginajax(request):
form = LoginForm(request.POST)
#redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
if request.POST:
#errors = manipulator.get_validation_errors(request.POST)
if form.is_valid():
if request.is_ajax:
user = authenticate(username = request.POST['username'],password = request.POST['password'])
if user is not None:
redirect_to = '/home/%s/'%user
else:
redirect_to = '/accounts/activate/'
return HttpResponse(redirect_to)
else:
return HttpResponse("False")
else:
return HttpResponse(form.errors)
脚本.js
$('#loginform').submit(function(e){
$.ajax({
type:"POST",
url:"/accounts/login/ajax/",
data:$('#loginform').serialize(),
success: function(msg){
window.location = msg;
}
});
e.preventDefault();
});
怀疑
我无法理解它何时返回重定向字符串,它说用户未通过身份验证并将我重定向到注册页面,请帮助