python - Trying to Query on Login and based on email and password return First Name -
i have sqlite database with: first_name email password andrew t@t.com abcde
i using check if there matching email , 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 try print first_name query did above error 'too many values unpack'
this happening because get() method expecting keyword arguments: https://docs.djangoproject.com/en/1.11/ref/models/querysets/#get
the queryset returned filter()
method contain more 1 entry: https://docs.djangoproject.com/en/1.11/ref/models/querysets/#filter , should specify expected value requested field.
one of ways access value is:
print name.get(first_name='andrew').first_name
on other hand, limit filter query:
user.usermanager.filter(email = postdata['email'], password = postdata['password'])[:1]
or use get()
method straightway , access field value directly:
user = user.usermanager.get(email = postdata['email'], password = postdata['password']) print user.first_name
Comments
Post a Comment