本文整理汇总了Python中django.template.context.Context.get方法的典型用法代码示例。如果您正苦于以下问题:Python Context.get方法的具体用法?Python Context.get怎么用?Python Context.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.template.context.Context
的用法示例。
在下文中一共展示了Context.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import get [as 别名]
def render(self, loader):
"""
Function - create html structure of folder's tree
Parameters
==========
loader - django.template.loader object
"""
if loader is django.template.loader:
ctx = Context()
t = loader.get_template('tinymce_images_foldertree.html')
if self.is_top():
ctx['is_top'] = 1
else:
ctx['relpath'] = self.path()
ctx['path'] = self._path
ctx['files_count'] = self.get_files_count()
ctx['folders_count'] = self.get_folders_count()
# for each item calls render function
for item in self._items:
ctx['inner'] = ctx.get('inner', '') + item.render(loader)
return t.render(ctx)
示例2: test_sitecats_url
# 需要导入模块: from django.template.context import Context [as 别名]
# 或者: from django.template.context.Context import get [as 别名]
def test_sitecats_url(self):
tpl = '{% load sitecats %}{% sitecats_url %}'
self.assertRaises(TemplateSyntaxError, render_string, tpl)
# testing UNRESOLVED_URL_MARKER
context = Context({'my_category': self.cat1, 'my_list': self.cl_cat1})
tpl = '{% load sitecats %}{% sitecats_url for my_category using my_list %}'
result = render_string(tpl, context)
self.assertEqual(result, UNRESOLVED_URL_MARKER)
# testing ModelWithCategory.get_category_absolute_url()
self.cl_cat1.set_obj(self.art1)
expected_url = '%s/%s' % (self.cat1.id, self.art1.title)
tpl = '{% load sitecats %}{% sitecats_url for my_category using my_list %}'
result = render_string(tpl, context)
self.assertEqual(result, expected_url)
tpl = '{% load sitecats %}{% sitecats_url for my_category using my_list as someurl %}'
render_string(tpl, context)
self.assertEqual(context.get('someurl'), expected_url)
# testing CategoryList.show_links
tpl = '{% load sitecats %}{% sitecats_url for my_category using my_list %}'
result = render_string(tpl, Context({'my_category': self.cat2, 'my_list': self.cl_cat2}))
self.assertEqual(result, str(self.cat2.id))