我的 Django 应用程序部署在 Heroku 上,我在那里使用 Postgres 和 MySQL 进行开发。我无法让用户(手动)登录,我收到此错误:
DatabaseError at /login/
current transaction is aborted, commands ignored until end of transaction block
查了代码,发现问题出在django.contrib.auth.authenticate
这是我的观点的代码:
if request.method == 'POST':
username = request.POST.get('username')
print username
password = 'none'
try:
user = User.objects.create_user(username, 'none', password)
user.save()
print user
fb_user_id = request.POST.get('fb_user_id')
print fb_user_id
full_name = request.POST.get('full_name')
print full_name
hostname = request.get_host()
invite_link = hostname + '/referal/'+str(short_url.encode_url(int(fb_user_id)))
print invite_link
# Create a UserProfile object that references user.
profile = UserProfile(
user = user,
fb_user_id = fb_user_id,
username = username,
full_name = full_name,
invite_link = invite_link
)
profile.save()
print profile
settings = Setting(user=profile)
settings.save()
print settings
print "success"
return HttpResponse('success')
except:
print "error"
# Authenticate the user
user = authenticate(username=username,password='none')
print user
if user is not None:
print "user is not None: ", user
if user.is_active:
print "loggin user in "
login(request, user)
return HttpResponseRedirect('/')
else:
print user,
print "user is none"
else:
return HttpResponse('not a post ')
return HttpResponse('fail')
当我尝试使用注册用户登录时,我在日志中看到的最后一件事是打印在except
块中的“错误”。在开发环境中,一切都按预期工作!以前有人遇到过这个问题吗?
编辑 实际上通过管理面板的身份验证工作得很好,用户注册也很完美。