我有一个login
带有自定义功能的authenticate
功能。
def authenticate(username='username', password='password'):
try:
return GalaxyUser.objects.get(username=username, password=password)
except GalaxyUser.DoesNotExist:
return None
def login_backend(request):
if request.method == 'POST':
username = request.POST['username']
username1 = ''.join(username)
password = request.POST['password']
password = ''.join(password)
password1 = hashlib.sha1(password).hexdigest()
user = authenticate(username=username1, password=password1)
login(request, user)
if user is None:
return HttpResponseRedirect('/unsuccessful/')
else:
return HttpResponseRedirect('/successful/')
else:
return render_to_response('login_backend.html', context_instance=RequestContext(request))
我没有被重定向到成功或不成功。但是,我收到此错误:
Traceback:
File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/zurelsoft/workspace/genelaytics/fileupload/backend.py" in login_backend
21. login(request, user)
File "/usr/local/lib/python2.6/dist-packages/django/contrib/auth/__init__.py" in login
73. request.session[BACKEND_SESSION_KEY] = user.backend
Exception Type: AttributeError at /login_backend/
Exception Value: 'GalaxyUser' object has no attribute 'backend'
我究竟做错了什么?GalaxyUser
是我的模型名称,backend
是我的视图代码所在的位置。