我无法在我的django项目中运行python脚本。
mkdir scripts
创建了一个目录touch scripts/__init__.py
touch scripts/update_keyword.py
创建我的python脚本
def run():
# Fetch all questions
print("run script")
然后我在以下命令的帮助下运行我的脚本:
python manage.py runscript update_keyword.py
现在我收到以下错误:
Unknown command: 'runscript'
Type 'manage.py help' for usage.
我关注了这个博客https://django-extensions.readthedocs.io/en/latest/runscript.html。请帮助。
Django不知道这个命令,因为它没有列在任何地方。如果要使用manage.py
运行命令,请使用Django's Admin Command。
编辑或者如果你真的想因某些原因使用django_extensions
,请使用他们的GitHub docs作为参考。在那里它声明你需要将此应用程序添加到INSTALLED_APPS
:
INSTALLED_APPS = (
...
'django_extensions',
...
)
检查安装:
https://django-extensions.readthedocs.io/en/latest/installation_instructions.html
我猜你错过了这个:
INSTALLED_APPS = (
...
'django_extensions',
)