0

I am using pyramid framework with BD postgres, I am doing a login, but I have the following error "Attribute error: Type object" Client "has no attribute" get ""."

@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 {}
GabBeG
  • 1
  • 1

2 Answers2

1

The error describes the issue. This line is the problem:

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

The object Client does not have an attribute of get. Sorry, I have no clue what that object could be based on the information provided.

I suggest working through the official Pyramid SQLAlchemy + URL dispatch wiki tutorial. Although it uses SQLite for a database, the concepts apply to Postgres as well. The step on authentication has pertinent details for your specific issue, too.

Steve Piercy
  • 10,144
  • 1
  • 31
  • 49
0

If im guessing right you are probably trying to authenticate user.

First name your variables appropriately:

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

Then query the Client by email (im guessing you are using SQLAlchemy):

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

If client exists for given email then check password hashes(search the web about password security, example solutions: Salt and hash a password in python)

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