3
You need to move the tasks to the background (so they donβt block the web process). One of the most popular ways to do this is to use a messaging/task queue.
Celery is one of the most popular distributed task queues, and coupled with the django-celery application makes this trivial.
First you need to setup celery (which is as simple as pip install -U celery
); and one of the many messaging brokers that it supports. The most popular one is RabbitMQ; but for quick and dirty set ups you can also use your existing database as a message broker.
Finally, since this is a common problem solved by celery+django, there is django-celery-email which takes care of the rest.
3
You might want to look into the django-mailer project, which encapsulates this functionality β it does this via crons, rather than using a task queue. Iβve been using it for a while with good results.
- [Django]-Django: Formset for adding captions to uploaded images
- [Django]-Django step through the code
- [Django]-Django β CreateView β Send a custom Error Message if model form is not valid
- [Django]-Can't get django urls to work
- [Django]-'ContentType' object has no attribute 'model_class' in data migration
1
You can send mails in separate thread, for example:
t = threading.Thread(target=send_mass_email,
args=[messages],
kwargs={'fail_silently': True})
t.setDaemon(True)
t.start()
or just use cron and django management commands =)
https://docs.djangoproject.com/en/dev/howto/custom-management-commands/
- [Django]-Facet multiple fields on search query set
- [Django]-How can I limit http method to a Django REST api
0
You can make it a management command and then setup a periodic cron job to send out the emails refer management command docs
- [Django]-AssertEqual fails even though the values are the same in python/django
- [Django]-How to get SelectDateWidget in Django to show different "Year" options
- [Django]-Django Administration: Delete record from custom user model