【问题标题】:Attribute error: Type object "Client " has no attribute "get属性错误:类型对象“Client”没有属性“get”
【发布时间】:2017-11-12 19:28:37
【问题描述】:

我正在使用带有 BD postgres 的金字塔框架,我正在登录,但出现以下错误“属性错误:类型对象”客户端“没有属性”获取“”。”

@view_config(route_name='login', renderer='templates/login.pt')

def login(request):
    a = request.params.get('login1')
    contrasenia = request.params.get('password1')
    if request.method == 'POST':
        if a and Client.get(a) == contrasenia:
            headers = remember(request, a)
            return HTTPFound('/', headers=headers)
    return {}

【问题讨论】:

    标签: python postgresql pyramid


    【解决方案1】:

    错误描述了问题。这行是问题所在:

        if a and Client.get(a) == contrasenia:
    

    对象Client 没有get 的属性。抱歉,根据提供的信息,我不知道该对象可能是什么。

    我建议使用官方 Pyramid SQLAlchemy + URL dispatch wiki tutorial。尽管它使用 SQLite 作为数据库,但这些概念也适用于 Postgres。身份验证步骤也包含针对您的特定问题的相关详细信息。

    【讨论】:

      【解决方案2】:

      如果我猜对了,您可能正在尝试对用户进行身份验证。

      适当地命名你的变量:

      email = request.params.get('email')
      password = request.params.get('password')
      

      然后通过电子邮件查询客户端(我猜你正在使用 SQLAlchemy):

      client = Session.query(Client).filter(Client.email == email).first()
      

      如果给定电子邮件存在客户端,则检查密码哈希(在网上搜索密码安全性,示例解决方案:Salt and hash a password in python

      if client.password_hash == hashing_func(password):
          return HTTPFound('/', headers=remeber(request, client.id))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-07
        • 2013-01-18
        • 1970-01-01
        • 2010-12-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多