Django:在后台发送电子邮件的最佳方法? [英] Django: Best way to send email in background?

查看:70
本文介绍了Django:在后台发送电子邮件的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Django发送电子邮件(使用Webfaction).但是,这非常慢,因此我想在后台发送电子邮件,即使尚未发送电子邮件也要向用户返回响应.

关于什么是最好的方法的任何想法?

我已阅读过有关芹菜的资料,但似乎需要很多步骤进行设置: http://www.artfulcode.net/articles/threading-django/

还是cron工作? http://docs.webfaction.com/software/general.html

您有经验的其他人吗?

解决方案

让我们对可能的解决方案进行简单的概述:

  1. 线程是不好的解决方案-因为线程仅在不发送响应之前才存在.

  2. Celery-是标准方法,很容易添加到django中(只需参阅很多有关django-celery的教程之一,您的任务就是使用数据库作为代理即可)

  3. Cron作业-并不是很好的程序员方式,因为您的代码将存储在您的存储库和系统crontab中.所以每次您都应该考虑一下.

  4. 其他方法是使用诸如Eventlet或Gevent之类的东西.绿色线程将在空闲状态下工作,并且对于您的标准任务-非常容易添加.缺点:-您应该对Greenlet有很多了解吗,应该小心捕获Greenlet中的错误.

我建议使用Celery,因为现在很容易添加它,包含很多教程和文档.此外,随着您的应用程序的发展,它也很容易.

I am sending email from Django (using Webfaction). This is, however, quite slow so I'd like to send the email in the background, returning a response to the user even if the email has not yet been sent.

Any ideas for what is the best way to do this?

I have read about celery, but it seems like a lot of steps to set it up: http://markliu.me/2011/sep/29/django-celery-on-webfaction-using-rabbitmq/ That's Ok, but I'd like to know that this is the way to go before trying it out.

How about threads? http://www.artfulcode.net/articles/threading-django/

Or cron jobs? http://docs.webfaction.com/software/general.html

Others that you have experience with?

解决方案

Let's make a simple overview of possible solutions:

  1. Threads are bad solution - because they are live only before your response is not send.

  2. Celery - is standard way, it's easy to add to django ( just see one of a lot of tutorial about django-celery, for your task using database as broker is enough)

  3. Cron jobs - is not really good programmer's way because your code will store in your repo, and in system crontab. SO everytime you should think about that.

  4. Other way is using something like Eventlet or Gevent. Green threads will live in work in idle, and for your standard task - is very easy to add. Disadvantages: - is you should understand a lot about greenlets, you should be careful for error catching in greenlet.

I recommend to use, Celery because, it's easy to add it now, a lot of tutorial and documentation. Also it's will easy grow up with your application.

这篇关于Django:在后台发送电子邮件的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆