Django相当于后端进程的paster
我在工作中使用 pylons,但我是 django 的新手。我正在制作一个 RSS 过滤应用程序,因此我希望有两个按计划运行的后端进程:一个用于抓取每个用户的 RSS 提要,另一个用于确定各个帖子相对于用户过去偏好的相关性。在 pylons 中,我只需编写粘贴命令来使用该数据更新数据库。 django 中有类似的东西吗? EG 有没有办法在非交互模式下运行相当于 python manage.py shell
的东西?
I use pylons in my job, but I'm new to django. I'm making an rss filtering application, and so I'd like to have two backend processes that run on a schedule: one to crawl rss feeds for each user, and another to determine relevance of individual posts relative to users' past preferences. In pylons, I'd just write paster commands to update the db with that data. Is there an equivalent in django? EG is there a way to run the equivalent of python manage.py shell
in a non-interactive mode?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这就是自定义管理命令的用途。
I think that's what Custom Management Commands are there for.
是的,这实际上就是我运行 cron 备份脚本的方式。如果您使用虚拟环境和项目设置,则只需加载 virtualenv 即可。
我希望你能遵循这一点,但是在
# manage.py shell
行之后,你可以编写代码,就像在manage.py shell
中一样你可以导入你的 virtualenv然后,
您可以将 django 项目添加到路径中
接下来,将 django 设置和 chdir 加载到 django 项目
中 之后,您的环境将被设置,就像您从
manage.py shell
开始一样然后您可以运行任何内容,就像在交互式 shell 中一样。
这是我的完整备份文件。我已将流程抽象为函数。这将被命名为
daily_backup
并放入cron.daily
文件夹中以每天运行。您可以了解如何设置环境并根据需要修改功能。Yes, this is actually how I run my cron backup scripts. You just need to load your virtualenv if you're using virtual environments and your project settings.
I hope you can follow this, but after the line
# manage.py shell
you can write your code just as if you were inmanage.py shell
You can import your virtualenv like so:
You can then add the django project to the path
Next you load the django settings and chdir to the django project
After this point your environment will be set just like if you started with
manage.py shell
You can then run anything just as if you were in the interactive shell.
Here is my backup file in full. I've abstracted the process out into functions. This would be named
daily_backup
and be put into thecron.daily
folder to be run daily. You can see how to set up the environment and modify the functionality as needed.听起来你的生活中需要一些twod.wsgi:http://packages.python.org/twod。 WSGI/
Sounds like you need some twod.wsgi in your life: http://packages.python.org/twod.wsgi/