django python manage.py runserver RuntimeError: Settings already configured

6.3k views Asked by At

I am quite new to Django and Python. My environ is Win7 and Python3.4. Now following the tutorial in Django Official Website to build a web app. At first, everything works quite well and output are all expected and correct. But today when I re-run the command "python manage.py runserver", it gives me very strange err message as follows. Help please, many thanks!

$ 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

There are 1 answers

1
Ozgur Vatansever On BEST ANSWER

From docs:

If you set DJANGO_SETTINGS_MODULE, access settings values somehow, then call configure(), Django will raise a RuntimeError indicating that settings have already been configured.

Also, it’s an error to call configure() more than once, or to call configure() after any setting has been accessed.

The problem is, by the time you call settings.configure() in mysite.polls.admin, settings were already configured. One option for suppressing the error would be adding some sanity check:

if not settings.configured:
    settings.configure()