如何通过cron作业运行django管理命令

编程入门 行业动态 更新时间:2024-10-24 22:30:58
本文介绍了如何通过cron作业运行django管理命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用一个名为django-mailbox的django应用程序。其目的是通过pop3和其他协议导入电子邮件,并将其存储在数据库中。我想定期通过一个时钟来做到这一点。在文档 django-mailbox.readthedocs/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 django-mailbox.readthedocs/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管理命令

本文发布于:2023-10-25 08:07:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1526410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:作业   命令   cron   django

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!