def merge_into(self, environment=None): """Push this bundle onto the environment, returning a new env.""" if environment is None: environment = get_env() for attr in ['globals', 'filters', 'tests']: getattr(environment, attr).update(getattr(self, attr)) return environment
def render_to_string(filename, context=None, environment=None): """Renders a given template name to a string.""" if context is None: context = {} if environment is None: environment = get_env() return environment.get_template(filename).render(context_to_dict(context))
def load(app_label, bundle_name, environment=None, reload=False): """Load a specified bundle into an/the environment.""" if environment is None: environment = get_env() bundle = get_bundle(app_label, bundle_name) if (bundle not in environment.loaded_bundles) or reload: bundle.merge_into(environment) environment.loaded_bundles.add(bundle) return bundle
def render_to_string(filename, context=None, environment=None): """Renders a given template name to a string.""" if context is None: context = {} if environment is None: environment = get_env() return environment.get_template(filename).render( context_to_dict(context))
# -*- coding: utf-8 -*- from django.http import HttpResponse import djanjinja local_env = djanjinja.get_env().copy() local_env.load('djanjinja', 'cache') def global_(request): """Renders a template which uses the global cache object.""" template = local_env.get_template('cache_global.txt') content = template.render().strip() return HttpResponse(content=content)