„
Django settings with
django-configurations
Bridge between Django’s module settings
system and class based configurations.
django-configurations
# mysite/settings.py
!
from configurations import Configuration
!
class Dev(Configuration):
DEBUG = True
django-configurati...
export DJANGO_SETTINGS_MODULE=
'mysite.settings'
!
export DJANGO_CONFIGURATION=
'Dev'
django-configurations
python manage.py runserver
--settings=mysite.settings
--configuration=Dev
django-configurations
Applies the class content to the containing
module before Django reads it.
django-configurations
It’s a hack. But it uses PEP 302.
django-configurations
# mysite/settings.py
!
from configurations import Configuration
!
!
class Dev(Configuration):
!
@property!
def LANGUAGES(s...
# mysite/settings.py
!
from configurations import Configuration
!
!
class PageCaching(object):
USE_ETAGS = True
!
class Pr...
• Mixins
• Facades
• Factories
• Adapters
!
• Setup hooks
• Values
What else?
Reduces the amount of validation and
setup code and lookup the process
environment of your software (os.environ).
!
Follow...
Value
BooleanValue
IntegerValue
FloatValue
DecimalValue
ListValue
TupleValue
SetValue
DictValue
EmailValue
URLValue
IPValu...
# mysite/settings.py
!
from configurations import (values,
Configuration)
!
!
class MySiteBase(Configuration):
DEBUG = val...
export DJANGO_DEBUG=true
Values
# mysite/settings.py
!
from configurations import (values,
Configuration)
!
!
class MySiteBase(Configuration):
DATABASES =...
export DATABASE_URL=
'postgres://user:pass@localhost/mydb'
Values
django-configurations.rtfd.org
!
@jezdez
Upcoming SlideShare
Loading in...5
×

Django settings with django-configurations

37,379

Published on

Published in: Technology

Django settings with django-configurations

  1. 1. „ Django settings with django-configurations
  2. 2. Bridge between Django’s module settings system and class based configurations. django-configurations
  3. 3. # mysite/settings.py ! from configurations import Configuration ! class Dev(Configuration): DEBUG = True django-configurations
  4. 4. export DJANGO_SETTINGS_MODULE= 'mysite.settings' ! export DJANGO_CONFIGURATION= 'Dev' django-configurations
  5. 5. python manage.py runserver --settings=mysite.settings --configuration=Dev django-configurations
  6. 6. Applies the class content to the containing module before Django reads it. django-configurations
  7. 7. It’s a hack. But it uses PEP 302. django-configurations
  8. 8. # mysite/settings.py ! from configurations import Configuration ! ! class Dev(Configuration): ! @property! def LANGUAGES(self):! return (Configuration.LANGUAGES + (('tlh', 'Klingon'),))! django-configurations
  9. 9. # mysite/settings.py ! from configurations import Configuration ! ! class PageCaching(object): USE_ETAGS = True ! class Prod(Configuration, PageCaching): DEBUG = False django-configurations
  10. 10. • Mixins • Facades • Factories • Adapters ! • Setup hooks • Values What else?
  11. 11. Reduces the amount of validation and setup code and lookup the process environment of your software (os.environ). ! Follows the Twelve-Factor methodology. Values
  12. 12. Value BooleanValue IntegerValue FloatValue DecimalValue ListValue TupleValue SetValue DictValue EmailValue URLValue IPValue RegexValue PathValue DatabaseURLValue CacheURLValue EmailURLValue SearchURLValue BackendsValue SecretValue ! and more.. Values
  13. 13. # mysite/settings.py ! from configurations import (values, Configuration) ! ! class MySiteBase(Configuration): DEBUG = values.BooleanValue(True) TEMPLATE_DEBUG = values.BooleanValue(DEBUG) Values
  14. 14. export DJANGO_DEBUG=true Values
  15. 15. # mysite/settings.py ! from configurations import (values, Configuration) ! ! class MySiteBase(Configuration): DATABASES = values.DatabaseURLValue( 'sqlite://') Values
  16. 16. export DATABASE_URL= 'postgres://user:pass@localhost/mydb' Values
  17. 17. django-configurations.rtfd.org ! @jezdez
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×