def children( self, parent_item: 'TreeItemBase', navigation_type: str, use_template: str, context: Context ) -> str: """Builds and returns site tree item children structure for 'sitetree_children' tag. :param parent_item: :param navigation_type: menu, sitetree :param use_template: :param context: """ # Resolve parent item and current tree alias. parent_item = self.resolve_var(parent_item, context) tree_alias, tree_items = self.get_sitetree(parent_item.tree.alias) # Mark path to current item. self.tree_climber(tree_alias, self.get_tree_current_item(tree_alias)) tree_items = self.get_children(tree_alias, parent_item) tree_items = self.filter_items(tree_items, navigation_type) tree_items = self.apply_hook(tree_items, f'{navigation_type}.children') self.update_has_children(tree_alias, tree_items, navigation_type) my_template = get_template(use_template) context.push() context['sitetree_items'] = tree_items rendered = my_template.render(context.flatten()) context.pop() return rendered
def render(self, context=None, request=None): # TODO: require context to be a dict -- through a deprecation path? if not isinstance(context, Context): if request is None: context = Context(context) else: # The following pattern is required to ensure values from # context override those from template context processors. original_context = context context = RequestContext(request) if original_context: context.push(original_context) return self.template.render(context)
def home(request): c = Context() menus = Menu.objects.all() menu_list = [] for menu in menus.values(): menu_list.append(menu['menu']) c['menu_list'] = menu_list contents = Content.objects.all() content_list = [] #for content in contents.values(): c.push() return render(request, 'Base.html', c)
def render(self, context=None, request=None): # A deprecation path is required here to cover the following usage: # >>> from django.template import Context # >>> from django.template.loader import get_template # >>> template = get_template('hello.html') # >>> template.render(Context({'name': 'world'})) # In Django 1.7 get_template() returned a django.template.Template. # In Django 1.8 it returns a django.template.backends.django.Template. # In Django 2.0 the isinstance checks should be removed. If passing a # Context or a RequestContext works by accident, it won't be an issue # per se, but it won't be officially supported either. if isinstance(context, RequestContext): if request is not None and request is not context.request: raise ValueError( "render() was called with a RequestContext and a request " "argument which refer to different requests. Make sure " "that the context argument is a dict or at least that " "the two arguments refer to the same request.") warnings.warn( "render() must be called with a dict, not a RequestContext.", RemovedInDjango20Warning, stacklevel=2) elif isinstance(context, Context): warnings.warn( "render() must be called with a dict, not a Context.", RemovedInDjango20Warning, stacklevel=2) else: if request is None: context = Context(context) else: # The following pattern is required to ensure values from # context override those from template context processors. original_context = context context = RequestContext(request) if original_context: context.push(original_context) return self.template.render(context)
if verbosity > 0: log.write("Found 'compress' tags in:\n\t" + "\n\t".join((t.template_name for t in compressor_nodes.keys())) + "\n") log.write("Compressing... ") count = 0 results = [] offline_manifest = SortedDict() for template, nodes in compressor_nodes.iteritems(): context = Context(settings.COMPRESS_OFFLINE_CONTEXT) template._log = log template._log_verbosity = verbosity for node in nodes: context.push() compiled_node = env.compile(jinja2.nodes.Template(node.body)) context.update(jingo.register.env.globals) context.update(jingo.register.env.filters) key = get_offline_hexdigest( Template.from_code( jingo.register.env, compiled_node, {} ).render(context)) try: context['compress_forced'] = True compiled_node = env.compile(jinja2.nodes.Template([node])) result = Template.from_code( env,
if verbosity > 0: log.write("Found 'compress' tags in:\n\t" + "\n\t".join((t.template_name for t in compressor_nodes.keys())) + "\n") log.write("Compressing... ") count = 0 results = [] offline_manifest = SortedDict() for template, nodes in compressor_nodes.iteritems(): context = Context(settings.COMPRESS_OFFLINE_CONTEXT) template._log = log template._log_verbosity = verbosity for node in nodes: context.push() compiled_node = env.compile(jinja2.nodes.Template(node.body)) context.update(jingo.register.env.globals) context.update(jingo.register.env.filters) key = get_offline_hexdigest( Template.from_code(jingo.register.env, compiled_node, {}).render(context)) try: context['compress_forced'] = True compiled_node = env.compile(jinja2.nodes.Template([node])) result = Template.from_code(env, compiled_node, {}).render(context) except Exception, e: raise CommandError("An error occured during rendering %s: " "%s" % (template.template_name, e))