文档地址 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 tomcat/resin安装配置 卸载系统自带的java tomcat安装配置 安装JDK resin安装配置 第二十八节课

    centos  tomcat/resin安装配置  卸载系统自带的java  tomcat安装配置  安装JDK   resin安装配置    第二十八节课 tomcat和java都不需要编译 tom ...

  2. C#基础整理(二)

    1.变量类型int.double.string.char.bool.decimal变量使用规则:先声明,再赋值,最后使用 2.命名规范:Camel:第一个单词首字母小写,其他单词首字母大写,其余字母小 ...

  3. 记一次mysql启动不了的问题

    在linux上用的是xampp,mysql启动没有报任何错误,但就是查找不到进程,于是找mysql错误日志,日志在哪?在lampp/var/mysql 以.err结尾的文件里.里面内容如下; /opt ...

  4. Django小项目web聊天

    WEBQQ的实现的几种方式 1.HTTP协议特点 首先这里要知道HTTP协议的特点:短链接.无状态! 在不考虑本地缓存的情况举例来说:咱们在连接博客园的时候,当tcp连接后,我会把我自己的http头发 ...

  5. 3.6 Templates -- Binding Element Class Names(绑定元素类名)

    1. 一个HTML元素的class属性可以像其他属性一样被绑定: <div class={{priority}}> Warning! </div> 生成的HTML <di ...

  6. 3.7 Templates -- Links

    一.The {{link-to}} Helper 1. 使用{{link-to}}创建一个指向route的链接: app/router.js Router.map(function() { this. ...

  7. 005-matlab2018a安装破解

    1.下载地址: 百度云下载链接:https://pan.baidu.com/s/1uTYAxVX1_Hx6nbsgf4W4kA 密码:asrw 官网下载地址: 2.解压. 3.双击setup.exe后 ...

  8. 1linux的基本命令

    查看命令的帮助信息man 命令名 文件操作touch 建立文件 (对于已存在文件,更新时间)cat 查看文件 (-n 自动加上行号)rm 删除文件cp 拷贝文件mv 移动/重命名文件more 分页查看 ...

  9. 牛客国庆集训派对Day7 Solution

    A    Relic Discovery 水. #include <bits/stdc++.h> using namespace std; int t, n; int main() { s ...

  10. OpenCV在未知相机内参数情况下的立体图像矫正方法及注意事项

    http://blog.sina.com.cn/s/blog_4298002e01013yb8.html 很多时候我们不知道摄像机的内参数矩阵,并且我们也不太关注内参数到底是多少,因为我们仅仅关心如何 ...