tornado基础知识想必大家已经学的差不多了。接下来小编会为大家带来稍微有点难度的知识点。看不懂的可以多学几遍。
众所周知,网站是一个极其复杂的系统,不可能只有一个静态页面。所以我们将上文的代码做一下改变:
<a href="https://www.gaodaima.com/tag/import" title="查看更多关于import的文章" target="_blank">import</a> tornado.ioloop import tornado.<a href="https://www.gaodaima.com/tag/web" title="查看更多关于web的文章" target="_blank">web</a> class MainHandler(tornado.web.RequestHandler): def get(self): self.write("Hello, world") settings = { 'template_path':'template', 'static_path':'static', } def make_app(): return tornado.web.Application([ (r"/", MainHandler), ],**settings) if __name__ == "__main__": app = make_app() app.listen(8888) tornado.ioloop.IOLoop.current().start()
www#gaodaima.com来源gao@dai!ma.com搞$代^码网搞代码
如上,我们添加了一个变量settings,但不要忘记在make_app后加上动态参数
template_path是你网页模板的路径,也就是你放网页的地方
static_path是你网页模板所需的css,js,图片等存放的地方
以上就是python tornado更改代码的方法。更多Python学习推荐:云海天Python教程网。
来源:搞代码网:原文地址:https://www.gaodaima.com