我正在尝试使用django-crontab 0.6(已安装)在Linux中设置一些cron作业。我添加了' django_crontab'到设置中的INSTALLED_APPS,我已使用:
指定了作业CRONJOBS = [
('0 0 * * *', 'proj.app.cron.update_entries'),
('0 * * * *', 'proj.app.cron.delete_queries')
]
当我尝试使用以下命令添加作业时:
python3 manage.py crontab add
......我收到错误。这是追溯:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.2/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.2/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python3.2/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.2/dist-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python3.2/dist-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
File "/usr/lib/python3.2/importlib/__init__.py", line 124, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/lib/python3.2/importlib/_bootstrap.py", line 824, in _gcd_import
raise ImportError(_ERR_MSG.format(name))
ImportError: No module named django_crontab
我正在使用Django 1.8.4。
答案 0 :(得分:1)
看起来有一个关于它的错误:https://github.com/kraiz/django-crontab/issues/20
“正确的module_path是myapp.cron而不是myproj.myapp.cron”
请您尝试以下代码:
CRONJOBS = [
('0 0 * * *', 'app.cron.update_entries'),
('0 * * * *', 'app.cron.delete_queries')
]
答案 1 :(得分:0)
问题是django-crontab是用pip-2.7安装的,因此Python 3.x无法使用它。