如何通过cron作业运行django管理命令 [英] How can I run a django management command by cron job

查看:139
本文介绍了如何通过cron作业运行django管理命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个名为django-mailbox的django应用程序。其目的是通过pop3和其他协议导入电子邮件,并将其存储在数据库中。我想定期通过一个时钟来做到这一点。在文档 http://django-mailbox.readthedocs.org/en/最新/主题/ polling.html ,其中指出:



使用cron作业



您可以通过运行名为getmail的管理命令(可选地,您想要获取邮件的邮箱名称的参数)容易地消耗传入邮件。:

  python manage.py getmail 

现在我可以在命令中运行线路在本地,它的工作原理,但如果这被部署到一个只能通过URL访问的外部服务器,该命令将如何给出?

解决方案

如果您使用虚拟环境,请使用virtualenv

  * * * * * / path /中的python二进制文件/ virtualenv / bin / python /path/to/project/manage.py management_command 


I am working with a django app called django-mailbox. The purpose of this is to import email messages via pop3 and other protocols and store them in a db. I want to do this at regular intervals via a chron. In the documentation http://django-mailbox.readthedocs.org/en/latest/topics/polling.html it states:

Using a cron job

You can easily consume incoming mail by running the management command named getmail (optionally with an argument of the name of the mailbox you’d like to get the mail for).:

python manage.py getmail

Now I can run this at the command line locally and it works but if this was deployed to an outside server which was only accessible by a URL how would this command be given?

解决方案

If you are using a virtual env use the python binary from the virtualenv

* * * * * /path/to/virtualenv/bin/python /path/to/project/manage.py management_command

这篇关于如何通过cron作业运行django管理命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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