如何通过cron作业运行django管理命令 [英] How can I run a django management command by cron job
问题描述
使用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屋!