jinja 2 filter 使用
文档地址 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 使用的更多相关文章
- [flask] jinja自定义filter来过滤html标签
问题描述 数据库存储了html格式的博客文章,在主页(index)显示的时候带有html标签,如何过滤掉呢? 解决方案 用jinja自定义filter过滤掉html标签 我是用的工厂函数,因此在工厂函 ...
- django 操作数据库--orm(object relation mapping)---models
思想 django为使用一种新的方式,即:关系对象映射(Object Relational Mapping,简称ORM). PHP:activerecord Java:Hibernate C#:Ent ...
- flask的模板引擎jinja入门教程 包含一个通过网络实时传输Video视频流的示例
本文首发于个人博客https://kezunlin.me/post/1e37a6/,欢迎阅读最新内容! tutorial to use python flask jinja templates and ...
- JavaWeb——Filter
一.基本概念 之前我们用一篇博文介绍了Servlet相关的知识,有了那篇博文的知识积淀,今天我们学习Filter将会非常轻松,因为Filter有很多地方和Servlet类似,下面在讲Filter的时候 ...
- 以bank account 数据为例,认识elasticsearch query 和 filter
Elasticsearch 查询语言(Query DSL)认识(一) 一.基本认识 查询子句的行为取决于 query context filter context 也就是执行的是查询(query)还是 ...
- AngularJS过滤器filter-保留小数,小数点-$filter
AngularJS 保留小数 默认是保留3位 固定的套路是 {{deom | number:4}} 意思就是保留小数点 的后四位 在渲染页面的时候 加入这儿个代码 用来精确浮点数,指定小数点 ...
- 挑子学习笔记:特征选择——基于假设检验的Filter方法
转载请标明出处: http://www.cnblogs.com/tiaozistudy/p/hypothesis_testing_based_feature_selection.html Filter ...
- [模拟电路] 2、Passive Band Pass Filter
note: Some articles are very good in http://www.electronics-tutorials.ws/,I share them in the Cnblog ...
- AngularJS过滤器filter-时间日期格式-渲染日期格式-$filter
今天遇到了这些问题索性就 写篇文章吧 话不多说直接上栗子 不管任何是HTML格式还是JS格式必须要在 controller 里面写 // new Date() 获取当前时间 yyyy-MM-ddd ...
随机推荐
- mongodb 的使用
install: 1.ubuntu用deb安装. 2.下载压缩文件,绿色的,不用安装. 推荐此方法. 配置dbpath: 1.用deb安装的,会在 /etc 目录下 创建mongodb.conf ...
- 窄依赖与宽依赖&stage的划分依据
RDD根据对父RDD的依赖关系,可分为窄依赖与宽依赖2种. 主要的区分之处在于父RDD的分区被多少个子RDD分区所依赖,如果一个就为窄依赖,多个则为宽依赖.更好的定义应该是: 窄依赖的定义是子RDD的 ...
- PAT 1102 Invert a Binary Tree[比较简单]
1102 Invert a Binary Tree(25 分) The following is from Max Howell @twitter: Google: 90% of our engine ...
- 线程,协程,IO模型
理论: 1.每创造一个进程,默认里面就有一个线程 2.进程是一个资源单位,而进程里面的线程才是CPU上的一个调度单位 3.一个进程里面的多个线程,是共享这个进程里面的资源的 4.线程创建的开销比进程要 ...
- 026-B树(一)
1.内节点:非根非叶子节点,即非根的分支节点. 2.名称:B-树=B树=平衡多路查找树. 3.定义:m阶B树. (0).根节点孩子数rootChildNum范围:若没有孩子节点则孩子数为0,若有孩子则 ...
- active admin常用配置
ActiveAdmin.register Post do permit_params :title, :content, :deadline, :status menu parent: "论 ...
- MapReduce: number of mappers/reducers
14 down vote It's the other way round. Number of mappers is decided based on the number of splits. I ...
- c++编译时打印宏定义
#pragma message("this is message") #pragma message只能打印字符串,如果想打印任何宏定义可使用: #define PRINT_MAC ...
- pyDay12
内容来自廖雪峰的官方网站. 1.可迭代对象(Iterable):可以直接作用于for循环的对象. 2.集合数据类型:如list.tuple.dict.set.str等. 3.generator:包括生 ...
- SQL学习笔记四(补充-2-1)之MySQL SQL查询作业答案
阅读目录 一 题目 二 答案 一 题目 1.查询所有的课程的名称以及对应的任课老师姓名 2.查询学生表中男女生各有多少人 3.查询物理成绩等于100的学生的姓名 4.查询平均成绩大于八十分的同学的姓名 ...