views:

24

answers:

1

Currently my login controller doesn't work because i can't seem to fetch the username and password.

I'm currently using something like this:

form_username = str(request.params.get('username'))

db_user = meta.Session.query(User).filter_by(username=form_username)
if db_user is None:
    return redirect('auth/error')

No matter which username is use, db_user always returns True and thus never goes to auth/error. I used the shell to play with this and i was able establish a connection with the database, so i'm not sure what i'm doing wrong here.

+2  A: 

You're on the right track; you just need to go one step further.

As you mention in the comments above, filter_by() returns a Query object.
You need to specify which method of the Query object you want to use to actually run the query and return some results.

In this case, I'd recommend first().

db_user = meta.Session.query(User).filter_by(username=form_username).first()

Documentation (my emphasis):

Return the first result of this Query or None if the result doesn’t contain any row. This results in an execution of the underlying query.

Adam Bernier
Yes, that seemed to work. Thanks!