--------------------静态文件--------------------
1、static_path:通过向web.Application类的构造函数传递一个名为static_path的参数来告诉Tornado从文件系统的一个特定位置提供静态文件
app = tornado.web.Application(
[(r'/', IndexHandler)],
static_path=os.path.join(os.path.dirname(__file__), "statics"),
)
2、对于静态文件目录的命名,为了便于部署,建议使用static
可以通过http://127.0.0.1/static/html/index.html来访问。而且在index.html中引用的静态资源文件,我们给定的路径也符合/static/...的格式,故页面可以正常浏览。
3、StaticFileHandler:可以通过tornado.web.StaticFileHandler来自由映射静态文件与其访问路径url。
1、tornado.web.StaticFileHandler是tornado预置的用来提供静态资源文件的handler。
2、
import os
current_path = os.path.dirname(__file__)
app = tornado.web.Application(
[
Tornado模板
最新推荐文章于 2020-03-26 12:30:49 发布
本文介绍了Tornado框架处理静态文件的方法,包括设置`static_path`,建议的目录命名,以及如何通过`StaticFileHandler`自定义静态文件路径。接着详细讲解了模板的使用,包括设置`template_path`,`render()`方法渲染模板,以及模板语法如变量与表达式、控制语句、函数、静态URL和自定义函数的使用。
摘要由CSDN通过智能技术生成