jinja2 使用教程
jinja2模板使用教程
网上很多教程都是直接copy官方文档。。。
jinja2的内置测试器的行为非常迷惑。。。iterable,mapping,string等的测试行为实际上跟python中的理解不同:
sw-office-lon-01 is an iterable: True
sw-office-lon-01 is a sequence: True
sw-office-lon-01 is a string: True4.22 is a number: True
4.22 is an integer: False
4.22 is a float: True65001 is a number: True
65001 is an integer: True
65001 is a float: False{'Ethernet1': 'Uplink to core'} is an iterable: True
{'Ethernet1': 'Uplink to core'} is a sequence: True
{'Ethernet1': 'Uplink to core'} is a mapping: True['1.1.1.1', '8.8.4.4', '8.8.8.8'] is an iterable: True
['1.1.1.1', '8.8.4.4', '8.8.8.8'] is a sequence: True
['1.1.1.1', '8.8.4.4', '8.8.8.8'] is a mapping: False
最后结论如下:
So what all of this means? Well, I suggest the following tests for each type of variable:
Number, Float, Integer - these work just as expected, so choose whatever fits your use case.
Strings - it's enough to use string test:
{{ my_string is string }}
Dictionary - using mapping test is sufficient:
{{ my_dict is mapping }}
Lists - this is a tough one, full check should tests if variable is a sequence but at the same time it cannot be a mapping or a string:
{{ my_list is sequence and my list is not mapping and my list is not string }}
In some cases we know dictionary, or a string, is unlikely to appear so we can shorten the check by getting rid of mapping or string test:
{{ my_list is sequence and my list is not string }}
{{ my_list is sequence and my list is not mapping }}
For the full list of available tests follow the link in References.
以上部分来自顶部的链接。
jinja2 使用教程相关推荐
- 「Python 网络自动化」目录汇总
目录 Netmiko NETCONF Nornir Paramiko Napalm NetBox TextFSM 其他 关于文章 关于我 Netmiko 「Python 网络自动化」Netmiko - ...
- python入门教程非常详细-Python该怎么入门?Python入门教程(非常详细)
Python要学多久可以学会,达到精通呢? 任何知识都是基础入门比较快,达到通晓的程序是需求时日的,这是一个逐渐激烈的进程. 通晓任何一门编程语言,都需求通过大量的实践来积累经验,解决遇到的各种疑难问 ...
- ansible1.7.2源码安装教程
ansible1.7.2源码安装教程 ================================================================================= ...
- 关于运维自动化工具saltstack的教程更新页面
saltstack的稳当写了不少,但是有点乱,现在把saltstack的教程归类在一起,方便大家查看,也方便自己 ! 自己写的教程,更像是 一个个的实例,而不是每个功能及模块的使用说明,后期再写的时候 ...
- Flask学习 黑马程序员-6节课入门Flask框架web开发视频(中途撤退,寻找py3教程)
文章目录 postman工具 get和post 如何给路由传参 解析 @app.route('')这个叫视图函数 Jinja2模板引擎 动态传参 注释.变量代码块以及控制代码块的使用 注释:ctrl+ ...
- 如何查看jinja2模板的上級_如何使用Python的Flask和谷歌app Engine来构建一个web app...
前言 如果您想在很短的时间内使用Python构建web应用程序,那么Flask是一个非常好的选择.Flask是一个小而强大的web框架.它也很容易学习和简单的代码. 在本教程中,我将向您展示如何使用A ...
- python神经网络多元函数_阿里达摩院推荐的最新400集python教程,据说懂中文就能上手...
小编的内心是强大的,网友虐我千百遍,我待网友如初恋,因为今天又给大家带来了干货,Python入门教程完整版,完整版啊!完整版! 为了吸取教训,小编一定要分享一下攻略,"怎样获得小编分享的教程 ...
- Werkzeug教程
http://chaoxz2005.blog.163.com/blog/static/15036542012863405266/ http://www.dajo.com.cn/a/boke/pytho ...
- python flask框架教程_Flask框架从入门到实战
Flask简介: Flask是一个使用 Python 编写的轻量级 Web 应用框架,基于 WerkzeugWSGI工具箱和 Jinja2模板引擎.使用 BSD 授权. Flask也被称为 " ...
最新文章
- CVPR 2022放榜!录用 2067 篇,接收数量上升24%
- Realm及相关对象——《跟我学Shiro》
- Spring Boot-场景启动器
- PHP中的常见魔术方法功能作用及用法实例
- WIN8 打开图片内置管理员无法激活此应用
- 使用IDM继续下载会话过期的文件
- SpringCloud 之客户端负载均衡策略
- 大数据技术原理与应用:期末考点总结
- 服务器虚拟cpu,服务器虚拟化 vcpu与内存配比
- 使用matplotlib画对数函数图像
- unity上线流程_新的Unity商店上线了
- 佛法在世间不离世间觉离世求佛法犹如觅兔角
- 复杂性研究简介——从西蒙到霍兰
- Hoeffding不等式的证明
- 周易六十四卦——泽天夬卦
- 一元函数积分学2_不定积分的分部积分法
- linux下删除空行的几种方法
- C/C++常用函数汇总
- C语言函数的基础运用-----二项式定理的运用
- 学计算机的女生最后都怎么样了?
热门文章
- 【Deno】极简入门
- 软工产品调研分析(成员)
- vue.js搭建个人博客
- HOT 100(一)
- 基于Python的2013-2018全国城市空气质量分析
- AD18层次原理图绘制
- 什么是Serverless?有哪些应用?终于有人讲明白了
- Codeforces Round #566 (Div. 2)-E. Product Oriented Recurrence
- c51语言 12864菜单设计 不带自库,12864显示花屏 - c51编程(单片机的c语言) - 51单片机学习论坛 www.51c51.com - Powered by Discuz!...
- 剪辑设置两个视频合成同屏幕播放