Django身份验证因DatabaseError而失败

时间:2012-11-30 21:51:41

标签: django heroku django-views

我的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块中。在开发环境中,一切都按预期工作! 以前有人遇到过这个问题吗?

修改 实际上,通过管理面板进行身份验证工作正常,用户注册也很完美。

0 个答案:

没有答案