Django:无法运行自定义命令 [英] Django: Can't run custom commands
问题描述
我写了一个简单的自定义命令,hello.py:
I've written a simple custom command, hello.py:
from django.core.management.base import NoArgsCommand
class Command(NoArgsCommand):
help = "prints hello world"
def handle_noargs(self, **options):
print "Hello, World!"
当我运行python manage.py hello它返回
When I run python manage.py hello it returns
未知命令:'hello'
Unknown command: 'hello'
- 我把它放在我应用程序下面的管理/命令目录中。 >
- 我已经将__init__.py文件添加到管理和命令目录。
- 我已经检查了我的应用程序在INTELALLED_APPS中的settings.py
- 我已经尝试将其安装在不同的应用程序和项目根目录中。
运行python管理。 py syncdb等很好。如果我在命令行中输入python,我可以导入django.core.management ok。
Running python manage.py syncdb etc is fine. And if I type python at the command line I can import django.core.management ok.
我知道我缺少一些明显的东西,但是找不出什么
I know I'm missing something obvious, but can't figure out what.
我如何调试这个,以找出为什么我的自定义命令不会运行?
How can I debug this to work out why my custom command won't run?
推荐答案
问题是我在PYTHONPATH上有另一个项目。 D'哦!我认为这是从那里拿起了settings.py,所以没有看到我的应用程序。在这个方向上指出的是我尝试运行python manage.py create_jobs myapp(从django命令扩展),并返回一个错误,指出该应用无法找到。 @knutin也提到INSTALLED_APPS。
The problem was that I had another project on my PYTHONPATH. D'oh! I think it was picking up the settings.py from there first so didn't see my app. What pointed me in this direction was I tried running python manage.py create_jobs myapp (from django command extensions) and it returned an error indicating the app couldn't be found. Also @knutin mentioned INSTALLED_APPS.
这篇关于Django:无法运行自定义命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!