python - Django: where is settings.py looking for imports, and why? -


i have django app common directory structure:

project ---manage.py ---app    ---__init__.py    ---settings.py    ---settings_secret.py    ---a bunch of other files app 

that settings_secret.py file contains variables secrets.py not want send github. reason, cannot seem import settings.py. first 5 lines of settings.py:

# django settings project.  debug = true template_debug = debug import os settings_secret import * 

which fails partial stacktrace:

file "/foo/bar/project/app/settings.py", line 5, in <module> settings_secret import * importerror: no module named 'settings_secret' 

to debug, created test file inside /project/ so:

from settings_secret import * print(variable_from_settings_secret) 

which worked charm. clearly, settings.py isn't looking in right place settings_secret. looking?

in settings.py, should do: from .settings_secret import *

it works . because proper syntax supposed be:

from app.settings_secret import *

removing app shorthand coding, same principle applies. need tell django directory (app), , specifying file in directory for.

if did, from settings_secret import *, telling django directory settings_secret, doesn't exist.

does make sense you?


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -