Skip to content

Commit 2dfae12

Browse files
authored
Merge pull request #4 from WnP/custom-template-class
Ability to definied a custom Template class
2 parents 5cd227b + 0e6adc4 commit 2dfae12

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

djangomako/backends.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ def __init__(self, parameters):
9292
# particular template URI
9393
options.setdefault('directories', self.template_dirs)
9494

95+
self.template_class = import_string(options.pop(
96+
'template_class', 'djangomako.backends.Template'))
97+
9598
self.engine = MakoEngine(**options)
9699

97100
def from_string(self, template_code):
@@ -104,7 +107,7 @@ def from_string(self, template_code):
104107
:return: Returns a compiled Mako template.
105108
"""
106109
try:
107-
return Template(self.engine.from_string(template_code))
110+
return self.template_class(self.engine.from_string(template_code))
108111
except mako_exceptions.SyntaxException as exc:
109112
raise TemplateSyntaxError(exc.args)
110113

@@ -118,7 +121,7 @@ def get_template(self, template_name):
118121
:return: Compiled Template.
119122
"""
120123
try:
121-
return Template(self.engine.get_template(template_name))
124+
return self.template_class(self.engine.get_template(template_name))
122125
except mako_exceptions.TemplateLookupException as exc:
123126
raise TemplateDoesNotExist(exc.args)
124127
except mako_exceptions.CompileException as exc:
@@ -159,4 +162,4 @@ def render(self, context=None, request=None):
159162
context['static'] = static
160163
context['url'] = reverse
161164

162-
return self.template.render(**context)
165+
return self.template.render(**context)

0 commit comments

Comments
 (0)