Django:管理命令消失,我无法测试脚本
我有一个命令已全部设置完毕并正在运行,然后我为其设置了一个 Cron 作业,现在它从所有可用命令的 manage.py 帮助列表中消失了。
它是在 /app/management/commands/feed_update.py
它有一个带有 handle() 函数的 Command(BaseCommand) 类。
问题是我的脚本依赖于 app.models,所以我什至无法运行该脚本来查看是否有问题以及为什么 manage.py 不会自动选择它。
有没有办法强制manage.py找到脚本?
谢谢。
编辑1: 我只是尝试做
manage.py shell
>> import app.management.commands.feed_update as fu
>> fu.Command.handle(fu.Command())
,一切都很好。我只是不明白为什么它不允许我通过manage.py运行它
。每个文件夹中都有 __init__.py
文件。
编辑2: 该应用程序安装在 Settings.py 中,是我的主要应用程序,为我的网络内容提供服务,因此我绝对确定它已安装。
它无法在 Cron 中或当我通过终端进入时找到该命令(即使我的其他应用程序的命令显示正确)。
I had a command all set up and working, then I set up a Cron job for it and now it disappeared from manage.py help's list of all available commands.
It is under
/app/management/commands/feed_update.py
and it has a Command(BaseCommand) class with a handle() function.
The problem is that my script has dependencies to app.models so I can't even run the script to see if something is wrong and why manage.py won't pick it up automatically.
Is there a way to force manage.py to find the script?
Thanks.
Edit 1:
I just tried doing
manage.py shell
>> import app.management.commands.feed_update as fu
>> fu.Command.handle(fu.Command())
and everything worked fine. I just don't understand why it wont let me run it through manage.py
I have __init__.py
files in every folder..
Edit 2:
The app is installed in Settings.py and is my main app that serves my web content so I am absolutely certain it is installed.
It can't find the command either in Cron or when I go in through the terminal (even though my other apps' Commands show up correctly).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它需要位于
settings.INSTALLED_APPS
中列出的应用程序内。如果它似乎已经存在,您确定 cron 作业正在使用正确的 settings.py 吗?
It needs to be inside an application that is listed in
settings.INSTALLED_APPS
.If it seems to be there already, are you sure that the cron job is using the right settings.py?
我刚刚解决了一个与此几乎相同的问题,除了我使用的是 django-admin.py 。当您在不带参数的情况下运行 django-admin.py 时,在我的开发机器上完美运行的管理命令没有出现在显示的命令列表中。事实证明,如果您希望自定义管理命令起作用,则需要从项目的根文件夹中运行
django-admin.py
。I just solved a problem almost identical to this except I'm using
django-admin.py
. A management command which worked perfectly on my dev machine wasn't appearing in the list of commands shown when you rundjango-admin.py
without an argument. Turns out you need to rundjango-admin.py
from within the root folder of your project if you want custom management commands to work.