1

I need to find a person when he enters his mobile number or email in the login form. My raw() query goes like this:

user = Users.objects.raw('SELECT * FROM main_users WHERE mobile  = %s OR email = %s',[login_id],[login_id])

But I am always getting a error:

Exception Value: not enough arguments for format string

So, what's the correct format for getting this solved?

0

4 Answers 4

2

You should put parameters under the same list:

user = Users.objects.raw('SELECT * FROM main_users WHERE mobile  = %s OR email = %s',
                         [mobile, email])
Sign up to request clarification or add additional context in comments.

Comments

2

There is no need for a raw query here.

users = User.objects.filter(Q(mobile=login_id) | Q(email=login_id))

Comments

0

You can do this by any of these two ways as already said above:

from django.db.models import Q
users = User.objects.filter(Q(mobile=login_id) | Q(email=login_id))

or by using raw() method:

user = Users.objects.raw('SELECT * FROM main_users WHERE mobile  = %s OR email = %s',[login_id,login_id])

Comments

0

The upper solutions were not working for me. I solved by this in Python 3

user = Users.objects.raw("SELECT * FROM main_users WHERE mobile  = '%s' OR email = '%s' " %(mobile, email))

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.