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 ...
随机推荐
- leetcode——Search for a Range 排序数组中寻找目标下标范围(AC)
Given a sorted array of integers, find the starting and ending position of a given target value. You ...
- Spring源码解析(三)BeanDefinition的载入、解析和注册
通过上一篇源码的分析已经完成了BeanDefinition资源文件的定位,本篇继续分析BeanDefinition资源文件的载入和解析. AbstractBeanDefinitionReader的lo ...
- WebStorm mac下如何安装WebStorm + 破解
1.下载软件最好的地址就是官网了下载地址 选择好系统版本以后点击DOWNLOAD 下载Webstorm 2.安装双击下载好的安装包.将WebStromt拖入application文件夹,然后在La ...
- X-NUCA联赛WEB赛前指导write-up
第一关 审查代码发现有隐藏的连接,访问,flag一闪而过.打开burpsuite,设置好代理,然后重新访问,在历史里找相应的回复包,得到flag. 第二关 审查元素 修改按钮为可用 抓获一个POST包 ...
- SpringMVC—概述
mvc容器的实例化: http://blog.csdn.net/lin_shi_cheng/article/details/50686876 Spring的启动过程: 1: 对于一个web应用,其部署 ...
- 2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest Solution
A. Rikka with Minimum Spanning Trees 题意: 给出一个图,求最小生成树的个数和权值 思路: 因为数据随机,只有一个MST #include <bits/std ...
- 前端优化点(此文转载 http://mp.weixin.qq.com/s/6mVVKmqDL_xYl15AeoJTWg)
此文转载自:http://mp.weixin.qq.com/s/6mVVKmqDL_xYl15AeoJTWg (原文地址) 围绕前端的性能多如牛毛,涉及到方方面面,以下我们将围绕PC浏览器和移动端浏览 ...
- 为什么要用Zero-Copy机制?
考虑这样一种常用的情形:你需要将静态内容(类似图片.文件)展示给用户.那么这个情形就意味着你需要先将静态内容从磁盘中拷贝出来放到一个内存buf中,然后将这个buf通过socket传输给用户,进而用户或 ...
- Win10取消开机密码方法
1.开始菜单输入命令“netplwiz” 2.进入到用户账户页面,选择所需账户,把“要使用本计算机,用户必须输入用户名和密码”单选框取消勾选,点击应用 3.输入密码进行 这个时候会提示输入两次该账户的 ...
- nmon监控Linux服务器系统资源
本文转自:http://www.cnblogs.com/hyzhou/archive/2011/12/29/2305860.html 在实际的测试过程中,Loadrunner监控Linux系统资源不太 ...