Does the Jinja2 templating language have the concept of 'here' (current directory)?

后端 未结 4 1870
花落未央
花落未央 2020-12-05 06:54

Does Jinja2 support template-relative paths e.g. %(here)s/other/template.html, to include other templates relative to the current template\'s place in the files

4条回答
  •  鱼传尺愫
    2020-12-05 07:42

    According to the documentation for jinja2.Environment.join_path(), support for relative template paths is possible by overriding join_path() to implement "template path joining".

    class RelEnvironment(jinja2.Environment):
        """Override join_path() to enable relative template paths."""
        def join_path(self, template, parent):
            return os.path.join(os.path.dirname(parent), template)
    

提交回复
热议问题