由于您的函数只接受一个参数,所以login(request, user)此语句会导致login() takes one argument and got two的异常。在
将您的函数名更改为其他名称,例如my\u login(request)
希望这有帮助。
谢谢
已编辑
你的功能应该是这样的。在
def my_login(request):
if request.method=='POST':
username = request.POST['username']
password =request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return render_to_response('profile.html')
else:
print "Your account has been disabled!"#come back to me
else:
sentence = "Your username and password were incorrect."# come back to me
return render_to_response('login.html', {'sentence':sentence})
else:
return render_to_response('login.html')#come back to me
不完全确定这是否能解决问题,但这里似乎有一个问题:
在请求.POST是字典,在这种比较中永远不会求值为真。在
或许可以尝试将其改为:
^{pr2}$这至少可以让您进入代码的正确if/else部分。在
我认为的问题是,您通过声明同名的函数来重写django
login
函数,当该语句执行login(request, user)
时,该函数将变为递归函数。在由于您的函数只接受一个参数,所以
login(request, user)
此语句会导致login() takes one argument and got two
的异常。在将您的函数名更改为其他名称,例如my\u login(request)
希望这有帮助。 谢谢
已编辑
你的功能应该是这样的。在
相关问题 更多 >
编程相关推荐