Giter Site home page Giter Site logo

Comments (2)

vladcalin avatar vladcalin commented on May 18, 2024 1

Thanks for answering! This is what I was looking for! 👍

from dynaconf.

rochacbruno avatar rochacbruno commented on May 18, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.