2👍
Although my solution is not as complex as the ones above, they fit my simple needs: I have some imports in my settings.py file:
try:
from settings_local import *
except ImportError:
pass
try:
from settings_production import *
except ImportError:
pass
And then I have a settings_local.py file in my local development folder (which I don’t upload to the server) and where I overwrite local settings. Then I have a settings_production.py server where I keep settings needed for the production environment.
You can use this technique to import other settings files as well.
2👍
Just put it in any file you like and import it somewhere in your main settings file.
So you could set up new settings my_new_settings.py
anywhere django can reach, and import it at the end of your real settings.py
.
# settings.py
# ...
from my_new_settings import *
- [Django]-Understanding / mySQL aka tricking ForeignKey relationships in Django
- [Django]-Getting time of form submission in Django
- [Django]-Django problem with extends template tag
- [Django]-Saving a Pillow file to S3 with boto
- [Django]-Jenkins not failing on tests that fail in coverage
2👍
I’m not a pythonista, so my take might just be the most un-pythonic way to do this. Having said that, this is how I split the settings for our Django app:
Instead of a single settings.py
file, we have settings/__init__py
. It contains imports for all the settings sections, which are placed in the settings directory.
# settings/__init__.py
from .foo import *
from .bar import *
# settings/foo.py
FOO="test"
# settings/bar.py
BAR="quz"
From the perspective of the application, this is still the same old settings module; from yours, it’s a clean structure of configuration data.
- [Django]-Output log file through Ajax in Django
- [Django]-Django SendGrid how to pass unique_args in EmailMultiAlternatives mail object
- [Django]-TypeError: the first argument must be callable when I import a scheduler in my views.py file of django?
- [Django]-How do I resolve access denied aws s3 files?
- [Django]-Django: nested custom template tags
0👍
Create new_settings.py
file to contain part of settings.py
, and import that file wherever you need it.
- [Django]-How to find duplicate records based on certain fields in Django
- [Django]-How to start Django up programmatically