文档地址 http://jinja.pocoo.org/docs/templates/#builtin-filters

indent

indent(s, width=4, indentfirst=False)

Return a copy of the passed string, each line indented by 4 spaces. The first line is not indented. If you want to change the number of spaces or indent the first line too you can pass additional parameters to the filter:

{{ mytext|indent(2, true) }}
indent by two spaces and indent the first line too.

返回字符串,缩进相应的宽度

如果mytext 是一个html 元素 比如 <p> indent by two spaces and indent the first line too.</p>

将会变成 “<p> indent by two spaces and indent the first line too.</p>”

这不是我们想要的,这种情况下应该写成

{{ mytext|indent(2, true)|safe }}
<p>indent by two spaces and indent the first line too.</p>

safe(value)

Mark the value as safe which means that in an environment with automatic escaping enabled this variable will not be escaped.

safe 会将值自动转义成安全的值,但在

{{ mytext|indent(2, true)|safe }}

表示这个值是安全的,不需要转义,会将值 直接显示的模板中

。。。。。未完

 

jinja 2 filter 使用的更多相关文章

  1. [flask] jinja自定义filter来过滤html标签

    问题描述 数据库存储了html格式的博客文章,在主页(index)显示的时候带有html标签,如何过滤掉呢? 解决方案 用jinja自定义filter过滤掉html标签 我是用的工厂函数,因此在工厂函 ...

  2. django 操作数据库--orm(object relation mapping)---models

    思想 django为使用一种新的方式,即:关系对象映射(Object Relational Mapping,简称ORM). PHP:activerecord Java:Hibernate C#:Ent ...

  3. flask的模板引擎jinja入门教程 包含一个通过网络实时传输Video视频流的示例

    本文首发于个人博客https://kezunlin.me/post/1e37a6/,欢迎阅读最新内容! tutorial to use python flask jinja templates and ...

  4. JavaWeb——Filter

    一.基本概念 之前我们用一篇博文介绍了Servlet相关的知识,有了那篇博文的知识积淀,今天我们学习Filter将会非常轻松,因为Filter有很多地方和Servlet类似,下面在讲Filter的时候 ...

  5. 以bank account 数据为例,认识elasticsearch query 和 filter

    Elasticsearch 查询语言(Query DSL)认识(一) 一.基本认识 查询子句的行为取决于 query context filter context 也就是执行的是查询(query)还是 ...

  6. AngularJS过滤器filter-保留小数,小数点-$filter

    AngularJS      保留小数 默认是保留3位 固定的套路是 {{deom | number:4}} 意思就是保留小数点 的后四位 在渲染页面的时候 加入这儿个代码 用来精确浮点数,指定小数点 ...

  7. 挑子学习笔记:特征选择——基于假设检验的Filter方法

    转载请标明出处: http://www.cnblogs.com/tiaozistudy/p/hypothesis_testing_based_feature_selection.html Filter ...

  8. [模拟电路] 2、Passive Band Pass Filter

    note: Some articles are very good in http://www.electronics-tutorials.ws/,I share them in the Cnblog ...

  9. AngularJS过滤器filter-时间日期格式-渲染日期格式-$filter

    今天遇到了这些问题索性就 写篇文章吧 话不多说直接上栗子 不管任何是HTML格式还是JS格式必须要在  controller 里面写 // new Date() 获取当前时间 yyyy-MM-ddd ...

随机推荐

  1. blockchain 区块链的开发,基于python或node js

    现在很多人用node js做区块链的开发,因为点对点并发是区块链中的难点技术之一,而node js天然的对并发支持比较好,因此比较有优势. http://ecomunsing.com/build-yo ...

  2. java8中接口中的default方法

    在java8以后,接口中可以添加使用default或者static修饰的方法,在这里我们只讨论default方法,default修饰方法只能在接口中使用,在接口种被default标记的方法为普通方法, ...

  3. map.containsKey

    该方法判断Map集合对象中是否包含指定的键名.如果Map集合中包含指定的键名,则返回true,否则返回false. 语法  containsKey(Object key) . e.g public s ...

  4. pyDay15

    内容来自廖雪峰的官方网站. 1.Python提供的sum()函数可以接受一个list并求和,请编写一个prod()函数,可以接受一个list并利用reduce()求积. from functools ...

  5. Linux学习笔记之Linux通过yum安装桌面

    Centos系统最小化安装以后,进入默认是命令行模式,所以需要进一步安装桌面. 1,本文使用的是CentOS 7 Minimal版本. 2,启动linux操作系统,进入后没有图形界面,但是有时候还是希 ...

  6. RESTful源码学习笔记之RPC和 RESTful 什么区别

    REST,即Representational State Transfer的缩写.翻译过来是表现层状态转换.如果一个架构符合REST原则,就称它为RESTful架构.啥叫json-rpc?接口调用通常 ...

  7. Python Web学习笔记之为什么设计GIL

    GIL(global interpreter lock),全局解释器锁,是很多编程语言实现中都具有的特性,由于它的存在,解释器无法实现真正的并发.它也是 Python 中经常讨论的话题之一. Pyth ...

  8. bzoj1297 / P4159 [SCOI2009]迷路

    P4159 [SCOI2009]迷路 如果边权只有 0/1 那么不就是一个灰常简单的矩阵快速幂吗! 然鹅边权 $<=9$ 所以我们把每个点拆成9个点! 解决~ #include<iostr ...

  9. POI之Excel导出

    1,在maven的pom文件中添加依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId& ...

  10. nodejs 8 利用原生 util.promisify() 实现 promise.delay()

    Nodejs 8 在 util 包里新增了 promisify() .这个方法基本和 bluebird 的 promisify() 作用一样,即把最后一个参数是 callback 函数的函数变成返回 ...