0

How can we login with username or password in Django site and Django Admin pages?

I tried by creating custom user model and making email field as username field but I can don't want to login with either username or email.

I want to use any of both any time to login.

  • 1
    Possible duplicate of [how to use django login](https://stackoverflow.com/questions/37751775/how-to-use-django-login) – Sebastian Waldbauer Nov 13 '19 at 18:32
  • check out this one: https://stackoverflow.com/questions/44972983/allowing-both-email-and-username-login-in-django-project – ha-neul Nov 13 '19 at 18:40

1 Answers1

0

You can use { from django.db.models import Q

Example:

from django.db.models import Q
user = "username/eamil"
password= "your password"
user_check = models.YourModelName.objects.filter((Q(email = user)|Q(username = user)), password = password)

}

Abu Nayem
  • 26
  • 5
  • Welcome to StackOverflow. When posting code, paste it, select it, and then click the `{}` widget to render it as text. – Jeff Learman Nov 13 '19 at 19:54