Python全系列 教程
3567个小节阅读:5930.9k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
思考 : 网站如何向客户端返回一个漂亮的页面呢?
提示 :
html
、css
、js
HttpResponse()
的参数,响应给客户端xxxxxxxxxx
import tornado
class IndexHandler(web.RequestHandler):
def get(self):
arg = 'Template'
self.finish(f'<h1>Hello {arg}!!</h1>')
tornado.template
A simple template system that compiles templates to Python code.
Basic usage looks like:
xxxxxxxxxx
class IndexHandler1(web.RequestHandler):
def get(self):
arg = 'Template1'
t = template.Template(f'<h1>Hello {arg}!!</h1>')
self.finish(t.generate())
class IndexHandler2(web.RequestHandler):
def get(self):
arg1 = 'Template2'
t = template.Template('<h1>Hello {{arg}}!!</h1>')
self.finish(t.generate(arg = arg1))
class IndexHandler3(web.RequestHandler):
def get(self):
arg1 = 'Template3_file'
loader = template.Loader('./templates/')
self.finish(loader.load('index.html').generate(arg = arg1))
xxxxxxxxxx
<!-- templates/index.html -->
<h1>Hello {{arg}}!!</h1>
xxxxxxxxxx
class IndexHandler4(web.RequestHandler):
def get(self):
arg1 = 'render_Template3_file'
self.render('index.html',arg=arg1)
实时学习反馈
1. 在Tornado中,以下哪个不是使用模板的原因?
A 模板的代码,代码量少
B 开发的效率高
C 模板的复用性强
D 模板的执行效率高
2. 在Tornado中,哪个不能返回一个模板?
A 通过RequestHandler.render()
方法
B 通过template.Template.generate
方法
C 通过template.Template.load
方法
D 通过template.Loader.load
方法
答案
1=>D 2=>C