我有一个简单的注册表单,可以输入这个函数views.py
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User
def registerNewUser(request):
newUser = User.objects.create_user(request.POST["username"], request.POST["email"], request.POST["password"])
newUser.last_name = request.POST["lastName"]
newUser.first_name = request.POST["firstName"]
print newUser.last_name
user = authenticate(username = request.POST["username"], password = request.POST["password"])
print user
if user is not None:
if user.is_active:
login(request, user)
print "Login Successful"
else:
return HttpResponse(simplejson.dumps({"login" : "failed"}))
我可以看到新记录被插入到AuthUser
表中,但是登录失败并且 HttpResponse JSON 错误消息正在返回给客户端。此外,
print user
正在返回无
为什么?
最后一点:表格的last_login
字段显示与该字段相同的时间戳。auth_user
date_joined