python - django import a variable from server specific settings file -
python - django import a variable from server specific settings file -
i have next settings structure. placement of settings folder per autogenerated config. instead of having settings.py, have created settings folder, , contents below.
local.py local machine, , production.py production server.
both local.py , production.py inherit _base.py .
├── _base.py ├── __init__.py ├── local.py ├── production.py └── secrets.py
earlier, there 1 settings file, happily in views write -
the some_variable
different production , local.
from settings import some_variable
, worked well.
this how validate
- python manage.py validate --settings=settings.local
throws import error.
importerror: cannot import name some_variable
any ways go importing things in views file, , avoid import error.
thanks!
there few different patterns handling settings across different installations. perhaps simplest needs the 1 true way.
if want bit more complicated (in opinion) better:
http://bruno.im/2013/may/18/django-stop-writing-settings-files/ or http://django-configurations.readthedocs.org/en/latest/ or if you're feeling experimental, https://github.com/seddonym/bobsleigh (disclaimer: project , in stages). python django django-settings
Comments
Post a Comment