Skip to Content
可编程网络自动化
book

可编程网络自动化

by Jason Edelman, Scott S. Lowe, Matt Oswalt
January 2023
Intermediate to advanced
458 pages
14h 16m
Chinese
Posts & Telecom Press
Content preview from 可编程网络自动化
142
6
当用户载入该页面时,
Django
负责渲染模板。
Django
框架届时会填入
title
变量和
article_list
变量,用户接收到的是已经包含真实数据的页面。开发人员无须为用户想要
检索的所有内容编写静态
HTML
页面,由
We
b
应用程序的后端逻辑进行管理即可。
Django
Jinja
这两种模板语言非常相似(但并不等同),本章会深入讨论后
者。别担心语法,随后会讲到。目前只重点关注模板的概念及其所提供的价
值:一致性。
模板语言的数量众多,本章没有足够篇幅为你一一道来,但你应该知道它们的存在。单就
Python
而言
,就有多种选项,比如之前提到的
Django
Jinja
,另外还有
Mako
Genshi
其他语言(比如
Go
Ruby
)也有内建的模板系统
。再重申一次,诸如
Python
Go
这些
语言的重要工作就是使用数据填充模板,这一点务必记住,因此,这也是决定使用哪种模
板语言的首要因素。通常来说,最好使用针对该语言构建的模板系统。
6.1.2
 拓展模板应用
需要注意的是,模板的概念,尤其是本章中所讨论的这些,并不局限于任何单个用例,而
是可以应用于大部分基于文本的媒介。本章将详细介绍如何使用模板进行网络配置,但是
正如刚刚讲过的那样,模板也可以构建动态
We
b
页面。实际上,我们还能将模板应用于
更一般的用途,比如普通的报告。也许你只是从网络设备中拉取数据,希望根据这些数据
生成一份漂亮的报告并通过电子邮件将其发送给同事。示例
6-1
显示了一个
Jinja
模板的示
例,可用于生成包含
VLAN
列表的报告。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

弱监督学习实用指南

弱监督学习实用指南

Wee Hyong Tok, Amit Bahree, Senja Filipi
Python和NLTK实现自然语言处理

Python和NLTK实现自然语言处理

Posts & Telecom Press, Nitin Hardeniya
Go程序设计语言

Go程序设计语言

艾伦A. A.多诺万, 布莱恩W. 柯尼汉
Python机器学习案例精解

Python机器学习案例精解

Posts & Telecom Press, Yuxi (Hayden) Liu

Publisher Resources

ISBN: 9787115606181