Django 管理工具坏了?
Django admin tool broken?
我已经使用 pip 在 OS X 10.9.5 上安装了 django,一天下来一切正常。第二天我开火了,工具好像坏了。
现在,除了 "startproject" 之外,我发出的任何命令都会失败,并显示以下输出。我试过开始一个完全干净的项目,但我得到了同样的结果。
$ django-admin manage.py check
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 182, in fetch_command
settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
不确定它有多大帮助,因为这是一个新项目,但这是 manage.py 的输出:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testdjango.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
我试过 uninstall/reinstalling django。接下来我应该看哪里?
您的语法不正确。您应该输入
django-admin check
或
python manage.py check
话虽这么说; django-admin
仅在创建项目时有用。您应该使用 manage.py
脚本来完成项目特定的任务。来自 docs:
Generally, when working on a single Django project, it’s easier to use manage.py than django-admin. If you need to switch between multiple Django settings files, use django-admin with DJANGO_SETTINGS_MODULE or the --settings command line option.
我已经使用 pip 在 OS X 10.9.5 上安装了 django,一天下来一切正常。第二天我开火了,工具好像坏了。
现在,除了 "startproject" 之外,我发出的任何命令都会失败,并显示以下输出。我试过开始一个完全干净的项目,但我得到了同样的结果。
$ django-admin manage.py check
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 182, in fetch_command
settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
不确定它有多大帮助,因为这是一个新项目,但这是 manage.py 的输出:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testdjango.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
我试过 uninstall/reinstalling django。接下来我应该看哪里?
您的语法不正确。您应该输入
django-admin check
或
python manage.py check
话虽这么说; django-admin
仅在创建项目时有用。您应该使用 manage.py
脚本来完成项目特定的任务。来自 docs:
Generally, when working on a single Django project, it’s easier to use manage.py than django-admin. If you need to switch between multiple Django settings files, use django-admin with DJANGO_SETTINGS_MODULE or the --settings command line option.