Jinja2中的多级模板继承? [英] Multiple level template inheritance in Jinja2?

查看:472
本文介绍了Jinja2中的多级模板继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做html / css由贸易,我一直在工作和django项目作为模板设计师。我目前正在一个网站使用Jinja2,我已经使用了大约2个星期。我刚刚发现通过阅读文档Jinja2不支持多级别模板继承,因为在你不能做多个

I do html/css by trade, and I have been working on and off django projects as a template designer. I'm currently working on a site that uses Jinja2, which I have been using for about 2 weeks. I just found out through reading the documentation that Jinja2 doesn't support multiple level template inheritance, as in you can't do more than one

{% extends "foo" %}

现在我很确定你可以在Django中做到这一点,这是强大的,因为你可以指定一个基本模板,指定3或4个模板,然后使用这些基本模板构建您的页面的肉。是不是继承点,所以你有更多的权力抽象,所以你唯一真的搞砸独特的代码?

per rendering. Now I'm pretty sure you can do this in Django, which is powerful because you can specify a base template, specify 3 or 4 templates based on that, and then build the meat of your pages using those base templates. Isn't the point of inheritance so you have more power to abstract so your only really messing with unique code?

在任何情况下,我不知道该怎么做。我不知道是否有一些方法,我可以做它将工作,以及它可以与Django模板。我不是一个Django或Jinja(2)的专家,但我可以提供任何所需的信息。

In any case I have no idea what to do here. I don't know if there is some way I can do it that will work as well as it could with the Django templates. I'm not exactly an expert at either Django or Jinja(2) but I can provide any information needed.

推荐答案

文档写的是它,它似乎不支持继承(n)层次深。

The way the documentation worded it, it seemed like it didn't support inheritance (n) levels deep.


与Python不同,Jinja不支持
多重继承。所以你只能
有一个扩展标签调用每
渲染。

Unlike Python Jinja does not support multiple inheritance. So you can only have one extends tag called per rendering.

我不知道只是一个规则说1扩展每个模板....我现在知道,借助于jinja irc渠道的一些帮助。

I didn't know it was just a rule saying 1 extends per template.... I now know, with some help from the jinja irc channel.

这篇关于Jinja2中的多级模板继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆