Jinja2模板超级功能未使用Django呈现 [英] Jinja2 template super functions not rendered with django
问题描述
我有两个非常简单的模板,例如
I have two very simple templates like
index.html:
index.html:
<html>
<head>
</head>
<body>
{% block content %}hello{% endblock %}
</body>
</html>
和details.html
and details.html
{% extends "index.html" %}
{% block content %}{{ super() }} world{% endblock %}
但是当我使用details.html渲染视图时,出现此错误
but when i render a view with details.html i get this error
Could not parse the remainder: '()' from 'super()'
我需要一些导入吗?
(模板会正确渲染,直到我使用super()函数为止)
(templates are rendered properly until i use the super() function)
推荐答案
Django 1.7和更早版本本身不支持Jinja。除非您做了一些使用Jinja的操作,否则您的模板应该使用Django模板语言,并且您不能使用Jinja。
Django 1.7 and earlier do not support Jinja natively. Unless you've done something to use Jinja, your templates should be in Django template language, and you can't use Jinja.
Django 1.8将具有支持多个模板引擎,以及对Jinja2的本地支持。
Django 1.8 will have support for multiple template engines, and native support for Jinja2.
在Django模板语言中,您可以使用 {{block.super}}
可以从父模板访问该块的内容。
In Django template language, you can use {{ block.super }}
to access the content of the block from the parent template.
这篇关于Jinja2模板超级功能未使用Django呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!