flask基于jinjia2的模板继承(4)

视图函数:



@app.route("/extend") def extend(): return render_template("extend.html")

基础:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p>this is json</p>
<p>
{% if user %}
    {{ user.qq }}
    {% endif %}
</p>
<p>
    {% for i in list %}
        {{ i }}
    {% endfor %}
</p>
{% block content %}
{% endblock content %}
</body>
</html>

继承:

{% extends "index.html" %}
{% block content %}
    <h1>hello 9980</h1>
{% endblock content %}

结果:

 

 很显然,仅仅替换了动态数据

猜你喜欢

转载自www.cnblogs.com/topass123/p/13172516.html
今日推荐