コード例 #1
0
 def testSetContext(self):
     self.assertIsNone(template_helpers.GetCurrentContext())
     data = {'key': 'value'}
     with template_helpers.SetCurrentContext(data):
         ctxt = template_helpers.GetCurrentContext()
         self.assertIsNotNone(ctxt)
         self.assertEquals('value', ctxt['key'])
     self.assertIsNone(template_helpers.GetCurrentContext())
コード例 #2
0
def _DjangoRenderTemplateSource(template_source, context_dict):
  """Renders the given template source with the given values dict.

  Args:
    template_source: (str) The source of a django template.
    context_dict: (dict) The dictionary to use for template evaluation.
  Returns:
    (str) The expanded template.
  """
  t = django_template.Template(template_source)
  ctxt = django_template.Context(context_dict)
  with template_helpers.SetCurrentContext(ctxt):
    return t.render(ctxt)