1

I a have a SQLite Database with: first_name email password Andrew [email protected] abcde

I am using this to check if there is a matching email and password:

if User.userManager.filter(email = postData['email'], password = 
postData['password']):
            name = User.userManager.filter(email = postData['email'], password = postData['password'])
            print name.get('first_name')
            return "success"

When I try to print first_name from the query i did above I get error 'too many values to unpack'

1
  • you did not have encrypted password of user or passing encrpted password from POST request? Jul 25, 2017 at 17:30

1 Answer 1

1

This is happening because get() method expecting for keyword arguments: https://docs.djangoproject.com/en/1.11/ref/models/querysets/#get

The QuerySet returned by filter() method could contain more than one entry: https://docs.djangoproject.com/en/1.11/ref/models/querysets/#filter , so you should specify expected value for the requested field.

One of the ways to access this value is:

print name.get(first_name='Andrew').first_name

On the other hand, you could limit your filter query:

User.userManager.filter(email = postData['email'], password = postData['password'])[:1]

Or just use get() method straightway and access field value directly:

user = User.userManager.get(email = postData['email'], password = postData['password'])
print user.first_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.