文档地址 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. centos vim编辑器 第八节课

    centos  vim编辑器  第八节课 其他编辑器: nanogeditemacs 腾讯云上的vim版本~ VIM - Vi IMproved ~ ~ version 7.4.629 ~ by Br ...

  2. 如何确定Hadoop中map和reduce的个数--map和reduce数量之间的关系是什么?

    一般情况下,在输入源是文件的时候,一个task的map数量由splitSize来决定的,那么splitSize是由以下几个来决定的 goalSize = totalSize / mapred.map. ...

  3. Spark中ml和mllib的区别

    转载自:https://vimsky.com/article/3403.html Spark中ml和mllib的主要区别和联系如下: ml和mllib都是Spark中的机器学习库,目前常用的机器学习功 ...

  4. html编码常见的有utf-8和gb2312编码等,应该如何判断选择?

    html如何选择编码,常见utf-8和gb2312编码如何判断选择 一.首先了解目前国内中文网页常用编码是utf-8 还是gb2313. 比如: 百度搜索 网页使用utf-8 腾讯新闻 网页使用utf ...

  5. 72. Edit Distance(编辑距离 动态规划)

    Given two words word1 and word2, find the minimum number of operations required to convert word1 to  ...

  6. 20145106 java实验一

    因为之前就使用过eclipse所以本次试验开始阶段并没有遇到什么大问题,按照步骤做下来. 我的实验序号根据算法是第二个四则运算的实验. 加法: package ljp; public class he ...

  7. 2017-2018-1 Java小组-1623 第二周作业

    2017-2018-1 Java小组-1623 第二周作业 关于游戏软件的问题 讨论结果 20162301张师瑜 20162305李昱兴 20162306陈是奇 20162308马平川 2016231 ...

  8. Duilib应用修改程序图标方法

    本文向大家介绍如何修改duilib应用图标,对于win32或者mfc应用来说,我们可以在注册窗口类时指定WNDCLASS结构体的HIcon属性.那么duilib应用该怎样处理呢?大家都知道Window ...

  9. Python学习札记(二十三) 函数式编程4 sorted

    参考:sorted NOTE 1.sorted,快速排序,时间复杂度O(nlogn)渐进最优. #!/usr/bin/env python3 L = [] for i in range(10): L. ...

  10. dynamic load javascript file.

    $.ajax({ url : ("js/public/" + window.localStorage.getItem("lang") + ".js&q ...