Flask中基于Jiaja2的模板语法

版权声明:尊重他人劳动成果,转载请注明出处 https://blog.csdn.net/qq_41432935/article/details/82116917

什么是Jiaja2模板?

Jiaja2是Flask默认支持的模板引擎,它的主要作用是渲染模板
Jinjia2模板可以保存在任何基于文本的文件中,比如XML,HTML,CSV等,所有模板文件本身可以接受任何文件后缀。

官方文档解释:Jinja looks and behaves mostly like Python. Special delimiters are used to distinguish Jinja syntax from the static data in the template. Anything between {{ and }} is an expression that will be output to the final document. {% and %} denotes a control flow statement like if and for. Unlike Python, blocks are denoted by start and end tags rather than indentation since static text within a block could change indentation.

  1. 继承:{% extends “父模板路径” %}
  2. 数据块:{% block 块名 %} 。。。{% endblock %}
  3. 路由生成:{{ url_for(“模块名.视图名”) }}
  4. 静态文件加载 {{ url_for(‘static’, filename=”静态文件路径”) }}
  5. 条件语句:{% if 条件 %}。。。{% endif %}
{% extends "base.html"%}     
{%block content%}
    <p>这个是我们的最新子类模板</p>
{%endblock%}

猜你喜欢

转载自blog.csdn.net/qq_41432935/article/details/82116917
今日推荐