user9252255
user9252255

Reputation:

Django: Changing project folder / settings structure

I am currently trying to change from the default Django structure to that one.

enter image description here

I now copied all the files in the new folders, but when running python manage.py runserver --settings=settings.local it shows the following in my terminal:

Traceback (most recent call last):
  File "manage.py", line 16, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/core/management/__init__.py", line 317, in execute
    settings.INSTALLED_APPS
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
    self._setup(name)
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/Users/Marc/.local/share/virtualenvs/lumis-vJ5Odiz7/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'settings'

Can anyone see what I am doing wrong? I also changed in my wsgi.py and manage.py to the following:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

enter image description here

Upvotes: 0

Views: 3886

Answers (3)

nativelectronic
nativelectronic

Reputation: 862

if you are using Pycharm go to File > Settings > Language and Frameworks >Django and configure that

1)[checked]  Django support 
2) settings: config\settings.py
3)manage script: manage.py

enter image description here

But if you are using a independent console it should be works fine just with the ___init__.py file in the folder config ,and the configuration os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") in the manage.py file,using

python manage.py runserver

Upvotes: 0

Radico
Radico

Reputation: 356

You need to tell django where to look for settings module therefore you have to specify the module path in manage.py:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")

and in __init__.py inside settings folder add the following lines:

try:
    from config.settings.local import *
except:
    pass

Upvotes: 0

Niicodemus
Niicodemus

Reputation: 327

You need to turn the config/ directory into a python module by creating a blank config/__init__.py file, then configure your DJANGO_SETTINGS_MODULE like this in manage.py and config/wsgi.py:

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.local")

Then you should be able to just run ./manage.py runserver without the --settings option.

Upvotes: 1

Related Questions