-2

I am learning django and I am stuck with this problem.

How do I get the email address of all the users in Django. The user can be of any type like superuser, general user etc.

I tried the following but I am not getting email address of all the users.

user = User.objects.get(id=2)
user_email = user. Email
print(user_email)

I want something like a list of all the email addresses. Can someone please help me with it?

Anshul Gupta
  • 265
  • 2
  • 12

1 Answers1

3
email_list = list(User.objects.values_list("email", flat=True))

Read more about values_list https://docs.djangoproject.com/en/4.1/ref/models/querysets/#values-list

lucutzu33
  • 3,470
  • 1
  • 10
  • 24