Django Service Templates
With service templates is possible to do:
- Store your templates in database.
- Connect your templates with context.
- Render templates with Jinja2
Heat example
from dbtemplates import Template from django_service_templates.models import ServiceTemplate class HeatTemplate(ServiceTemplate): @cached_property def heat(self): return get_heat_client(**self.get_context()) @cached_property def stack_name(self): return slugify(self.label) @property def heat_kwargs(self): return { 'stack_name': self.stack_name, 'disable_rollback': True, 'parameters': self.clean_kwargs(), 'template': self.get_content(), 'environment': {} } def stack_create(self): try: response = self.heat.stacks.create(**self.heat_kwargs) except Exception as e: raise e self.add_message(response) return response
dbtemplate = Template.objects.create(name='My Jinja2 Template', content='{{ name }}') heat_template = HeatTemplate.objects.create(template=dbtemplate, context={'name': 'My name'}) heat_template.render() > 'My name' heat_template.stack_create()