def render(self, context={}):
"""Render's a template, context can be a Django Context or a
dictionary.
"""
# flatten the Django Context into a single dictionary.
context_dict = {}
if hasattr(context, 'dicts'):
for d in context.dicts:
context_dict.update(d)
else:
context_dict = context
# Django Debug Toolbar needs a RequestContext-like object in order
# to inspect context.
class FakeRequestContext:
dicts = [context]
context = FakeRequestContext()
# Used by debug_toolbar.
if settings.TEMPLATE_DEBUG:
from django.test import signals
self.origin = Origin(self.filename)
signals.template_rendered.send(sender=self, template=self,
context=context)
return super(Template, self).render(context_dict)
评论列表
文章目录