是否可以在特定日期自动运行 django 函数?

发布于 2024-09-12 05:28:46 字数 103 浏览 1 评论 0原文

在我的 django 项目中,如果数据库中的某些条目太旧,我希望能够自动删除它们。我可以编写一个函数来检查创建日期,如果它太旧,则将其删除,但我希望该函数定期自动运行。是否可以这样做? 谢谢

In my django project I would like to be able to delete certain entries in the database automatically if they're too old. I can write a function that checks the creation_date and if its too old, deletes it, but I want this function to be run automatically at regular intervals..Is it possible to do this?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

随风而去 2024-09-19 05:28:46

这就是cron 的用途。

This is what cron is for.

梦醒时光 2024-09-19 05:28:46

您最好阅读 Django 文档的这一部分 http://docs.djangoproject.com/en/1.2/howto/custom-management-commands/#howto-custom-management-commands

然后你可以将你的函数创建为 Django 管理命令并将其与 *nix 上的 cron(或 Windows 上的计划任务)结合使用,以按计划运行它。

有关 cron 的良好介绍指南,请参阅此 http://www.unixgeeks .org/security/newbie/unix/cron-1.html

You will be better off reading this section of the Django docs http://docs.djangoproject.com/en/1.2/howto/custom-management-commands/#howto-custom-management-commands

Then you can create your function as a Django management command and use it in conjunction with cron on *nix (or scheduled tasks on Windows) to run it on a schedule.

See this for a good intro guide to cron http://www.unixgeeks.org/security/newbie/unix/cron-1.html

撕心裂肺的伤痛 2024-09-19 05:28:46

你需要的是一个 cron 作业。

cron 作业是基于时间的作业调度程序。大多数网络托管公司都提供此功能,让您可以在选择的时间运行服务或脚本。大多数基于 Unix 的操作系统都具有此功能。

如果您在 stackoverflow 的姊妹网站 serverfault.com 上提出这个问题,您会得到更好的直接帮助。

What you require is a cron job.

A cron job is time-based job scheduler. Most web hosting companies provide this feature which lets u run a service or a script at a time of your choosing. Most Unix-based OSes have this feature.

You would have better direct help asking this question on serverfault.com, the sister site of stackoverflow.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文