文档地址 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. Eclipse中没有javax.servlet和javax.servlet.http包的处理办法

    使用Eclips开发JSP也需要这两个包:javax.servlet和javax.servlet.http:若提示没有javax.servlet包则安装如下处理办法解决: 如果你装了Tomacat,那 ...

  2. 从getApplicationContext和getApplication再次梳理Android的Application正确用法

    原文地址http://blog.csdn.net/ly502541243/article/details/52105466 原文地址http://blog.csdn.net/ly502541243/a ...

  3. swoole gets

    控制器调用: function gets() { $model = Model('ap_pic'); $model->select = ' id, size_type '; $gets['pag ...

  4. 38初识xml

    XML(可扩展标记语言)是一种用于记录多种数据类型的标记语言.使用XML可以将各类型的文档定义为容易读取的格式,便于用户读取.而且,在应用程序中使用XML,可以轻松实现数据交换. QT中提供两种访问X ...

  5. uva10417 概率DP

    这题 to[i][j] 为第i个人送j这个礼物的概率 我们用13进制进行压缩这个留下的的礼物的个数,这样我们将dp[i][k]表示为当第i个人放完礼物后得到的状态为k时的概率,那么通过记忆化搜索我们就 ...

  6. iOS重签名脚本

    unzip xxx.ipa //解压ipa rm -rf Payload/ xxx.app/_CodeSignature //删除旧签名 cp newEmbedded.mobileprovision ...

  7. springcloud7---hystrix

    目前使用eureka server完成了服务注册和服务发现,ribbon完成了客户端负载均衡.如果服务提供者的响应很慢那么服务消费者会强制等待,一直等到http请求超时,如果服务消费者还是其他的服务提 ...

  8. linux内核分析第八周-理解进程调度时机跟踪分析进程调度与进程切换的过程

    实验原理: 一.调度时机 不同类型的进程有不同的调度需求 第一种分类:        I/O-bound             频繁的进行I/O            通常会花费很多时间等待I/O操 ...

  9. 《Effective Java 2nd》第2章 创建和销毁对象

    目录 第1条:考虑使用静态工厂方法代替构造器 第2条:遇到多个构造器参数时考虑用构建器 第3条:用私有构造器或者枚举类型强化Singleton属性 第4条:通过私有构造器强化不可实例化的能力 第5条: ...

  10. [BZOJ1901]Dynamic Rankings

    Description 给定一个含有n个数的序列a[1],a[2],a[3]……a[n],程序必须回答这样的询问:对于给定的i,j,k,在a[i],a[i+1 ],a[i+2]……a[j]中第k小的数 ...