Jinja2模板超级函数不用django渲染

时间:2021-06-02 20:47:31

I have two very simple templates like

我有两个非常简单的模板,比如

index.html:

index.html的:

<html>
    <head>
    </head>
    <body>
        {% block content %}hello{% endblock %}
    </body>
</html>

and details.html

和details.html

{% extends "index.html" %}
{% block content %}{{ super() }} world{% endblock %}

but when i render a view with details.html i get this error

但是当我使用details.html渲染视图时,我收到此错误

Could not parse the remainder: '()' from 'super()'

do i need some import somewere?

我需要一些进口吗?

(templates are rendered properly until i use the super() function)

(模板正确呈现,直到我使用super()函数)

1 个解决方案

#1


1  

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.7及更早版本不支持Jinja。除非你已经使用了Jinja,否则你的模板应该是Django模板语言,你不能使用Jinja。

Django 1.8 will have support for multiple template engines, and native support for Jinja2.

Django 1.8将支持多个模板引擎,并支持Jinja2。

In Django template language, you can use {{ block.super }} to access the content of the block from the parent template.

在Django模板语言中,您可以使用{{block.super}}从父模板访问块的内容。

#1


1  

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.7及更早版本不支持Jinja。除非你已经使用了Jinja,否则你的模板应该是Django模板语言,你不能使用Jinja。

Django 1.8 will have support for multiple template engines, and native support for Jinja2.

Django 1.8将支持多个模板引擎,并支持Jinja2。

In Django template language, you can use {{ block.super }} to access the content of the block from the parent template.

在Django模板语言中,您可以使用{{block.super}}从父模板访问块的内容。