def func(ctx,*args,**kwargs): t = env.get_template(template) if takes_context: values = fn_(ctx,*args,**kwargs) else: values = fn_(*args,**kwargs) for k in ('request','user','STATIC_URL', 'csrf_token','MEDIA_URL','site','TIME_ZONE','messages'): if k in ctx: values[k] = ctx[k] return t.render( values )
def load_template(self, template_name, template_dirs=None): """ In the root directory, use jinja only for files with jinja extension In app directory, use it for all """ #app can be wrong jinja = DEFAULT_BINJA_TEMPLATE_EXTENSION root = template_name.strip("/").split("/")[0] _,ext = os.path.splitext(template_name) if ext is jinja or (root not in BINJA_EXCLUDE_FOLDERS and root != template_name): try: template = env.get_template(template_name) return template, template.filename except jinja2.TemplateNotFound: raise TemplateDoesNotExist(template_name) else: return super(LoaderMixin, self).load_template(template_name, template_dirs)