Integrating Mako with Django 1.8 Template Backend Subsystem
By Idego Group

Django 1.8 introduced support for multiple template engines, a significant architectural change that allowed developers to move beyond the default Django Template Language. The feature was community-funded through an Indiegogo campaign and represented a response to performance concerns with complex templates.
The new template backend system requires implementing a custom class that inherits from BaseEngine. This class must provide two methods: from_string() for compiling template code directly, and get_template() for loading templates by name. Both methods return Template objects with a render(context, request) signature.
A critical implementation detail involves properly handling the BaseEngine initialization. The parent class validates that all configuration parameters are consumed, so developers must explicitly copy and pop the OPTIONS dictionary before calling the superclass constructor.
Context processors present another consideration. Unlike Django's native template engine, alternative backends like Jinja2 and Mako do not natively support context processors. Implementing custom backends requires manually applying context processors within the template wrapper's render method.
The Mako implementation demonstrates creating a reusable base class that other template backends can extend. This base class handles context processor application and OPTIONS extraction, while specific engine implementations focus on engine initialization and exception translation.
Template selection becomes slightly less efficient when multiple backends are configured, as Django scans each registered backend. However, the django.template.loader module provides a using parameter that allows explicit backend specification, bypassing the exhaustive search.