Wednesday 15 July 2015

python - How can I create a script where it will print all email addresses of my Django users into a small .txt file? -


About 6000 users are using my Django app. I have recently searched for Mailchip and I All users would like to send a message about the website going down for a few days

Instead of copying and pasting every single email (about 6000), I wanted to know if there is a Python script or something that would write all the email addresses of each user in my app in small to .txt Could.

How can I go about doing this?

You can write one to get it. Import from Django.core.management.base Import CommandError from BaseCommand, django.contrib.auth.modelsUser class command (base command): def handle (auto, * argets, option **) : User_emails = User.objects.values_list ('email', flat = true) with Open ('myfile.txt', 'w +') as fh: fh.write ("," .join (list_username))

and in the command line:

  ./ management.py & lt; Management command_filname & gt;    

No comments:

Post a Comment