Comments (2)
Thanks for answering! This is what I was looking for! 👍
from dynaconf.
@vladcalin settings is a dict
like object, so when a default value is needed we can use get
I am using the following approach.
print(settings.MONGODB_HOST)
print(settings.MONGODB_PORT)
print(settings.MONGODB_DATABASE)
print(settings.get('MONGODB_USE_SSL', default=False))
print(settings.get('MONGODB_USERNAME')) # default is None
print(settings.get('MONGODB_PASSWORD'))
But if you want to define default values, another way would be using the global namespace DYNACONF
DYNACONF:
MONGODB_USE_SSL: false
MONGODB_USERNAME: null
MONGODB_PASSWORD: null
DEVEL:
MONGODB_DATABASE: devel
MONGODB_HOST: localhost
MONGODB_PORT: 27000
PRODUCTION:
MONGODB_DATABASE: production_stuff
MONGODB_HOST: mongodb.example.com
MONGODB_PORT: 10980
MONGODB_USERNAME: efe6398127928f1b2e9ef3207fb82663
MONGODB_PASSWORD: 1f048e5fb80c559a4ab4c6e79d940708
In that way when the value is not found in the specific namespace it is taken from the global.
settings.namespace('devel')
# taken from DEVEL:
print(settings.MONGODB_HOST)
print(settings.MONGODB_PORT)
print(settings.MONGODB_DATABASE)
# taken from DYNACONF: (the global namespace)
print(settings.MONGODB_USE_SSL)
print(settings.MONGODB_USERNAME)
print(settings.MONGODB_PASSWORD)
from dynaconf.
Related Issues (20)
- Django 4.2.5 and Dynaconf 3.2.2 (AttributeError) HOT 5
- .secrets.toml not read automatically HOT 4
- [bug] BoxKeyError: "dynaconf_merge_unique" with specific YAML files HOT 2
- [bug] TypeError for older versions of HVAC in read_secret_version method
- [RFC] Ability to change `SECRETS_FOR_DYNACONF` environment variable to something else
- [RFC] Make dynaconf CLI configurable for file to look at and validator to apply
- Use Validator default value when validation fails? HOT 5
- Nested setting disappears after validation HOT 2
- [RFC] parse True/False as boolean by default
- [bug] when using a validator with a default for nested data it parses value via toml twice
- [RFC] Stop setting default value inside validate method HOT 1
- [bug] Unable to load configuration files using the `*` wildcard HOT 1
- [bug] KeyError: '_bypass_evaluation' in Dynaconf 3.2.1 HOT 3
- [bug] Validation time increased more than 10 times in dynaconf 3.2.0 HOT 7
- [CI] `.coveragerc` is ignored on CI HOT 1
- [bug] two validators with defaults break string casting of lists in .env file
- [bug] Default value on empty string HOT 9
- [bug] `validate_on_update` causes `AttributeError: 'Settings' object has no attribute 'ENVIRONMENTS_FOR_DYNACONF'` HOT 2
- Add Python API documentation / Module reference to the documentation/website HOT 3
- [bug] `merge_enabled=True` causes list values to merge HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dynaconf.