django python manage.py runserver RuntimeError:已配置的设置

时间:2015-08-18 05:02:35

标签: python django django-settings django-dev-server

我是Django和Python的新手。我的环境是Win7和Python3.4。现在按照Django官方网站上的教程构建一个Web应用程序。起初,一切都运作良好,输出都是预期和正确的。但是今天当我重新运行命令“python manage.py runserver”时,它给出了我非常奇怪的错误消息,如下所示。请帮助,非常感谢!

$ python manage.py runserver 
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
    utility.execute()
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 312, in execute
    django.setup()
  File "C:\Python34\lib\site-packages\django\__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Python34\lib\site-packages\django\apps\registry.py", line 115, in populate
    app_config.ready()
  File "C:\Python34\lib\site-packages\django\contrib\admin\apps.py", line 22, in ready
    self.module.autodiscover()
  File "C:\Python34\lib\site-packages\django\contrib\admin\__init__.py", line 24, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "C:\Python34\lib\site-packages\django\utils\module_loading.py", line 74, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "D:\360\My Cloud\5 Software\26 Eclipse\1 Python\1TDD_Django\tdd_django\mysite\polls\admin.py", line 34, in <module>
    settings.configure()
  File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 58, in configure
    raise RuntimeError('Settings already configured.')
RuntimeError: Settings already configured.

1 个答案:

答案 0 :(得分:3)

来自docs

  

如果您设置 DJANGO_SETTINGS_MODULE ,以某种方式访问​​设置值,然后调用 configure(),Django将引发 RuntimeError ,表明设置已经已配置。

     

此外,多次调用configure()或在访问任何设置后调用configure()是错误的。

问题是,当您在 mysite.polls.admin 中调用settings.configure()时,已经配置了设置。抑制错误的一个选择是添加一些健全性检查:

if not settings.configured:
    settings.configure()