Write configuration schemas¶
As a Django application developer, you want to expose configuration directives. You want to make sure your application is well configured. As an example, you appreciate to mark some directives as required, and to provide default values for optional ones. But you do not want to re-invent the wheel about validation.
As a Django user, you do not want to bother about application configuration schemas. You just want it loaded when you register the application in INSTALLED_APPS.
This sections explains how to create with django-confit.
"""Custom configuration schema(s).""" import colander class DjangoConfitDemoConfigurationSchema(colander.MappingSchema): CONFITDEMO_HELLO = colander.SchemaNode( colander.String(), missing=colander.required, default='', )
In django-confit code, you will see some hacks around versions of applications. Yes, they are hacks. They are necessary because from the django-confit point of view, we do not know which version of the application is actually installed. So we have to write conditionals in order to support them as well as possible... But it is a true pain.
Just imagine the schema lives within the third-party application itself... As a consequence:
- one schema is enough. No need to manage concurrent schemas. The one for the current version is enough.
- the schema is updated along the application. It is part of the application’s release process.
- as an user, you do not have to find or write a schema for the application. There is an official one! You install the app, you get the schema!
Register your schema¶
In a project or a third-party application, register schemas in settings.CONFIT_SCHEMAS. See Configure.
In django-confit itself, make sure the schema can be loaded with django_confit.schemas.<APP>.ConfigurationSchema.
Notes & references