您现在的位置是:课程教程文章

python tornado如何更改代码?

2023-12-18 16:49课程教程文章 人已围观

tornado基础知识想必大家已经学的差不多了。接下来小编会为大家带来稍微有点难度的知识点。看不懂的可以多学几遍。


众所周知,网站是一个极其复杂的系统,不可能只有一个静态页面。所以我们将上文的代码做一下改变:

import tornado.ioloop
import tornado.web
 
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()


如上,我们添加了一个变量settings,但不要忘记在make_app后加上动态参数

template_path是你网页模板的路径,也就是你放网页的地方

static_path是你网页模板所需的cssjs,图片等存放的地方

以上就是python tornado更改代码的方法。更多Python学习推荐:PyThon学习网教学中心

课程教程:python tornado如何更改代码?

上一篇:如何使用python做一个聊天小程序?

下一篇:没有了

站点信息

  • 文章统计篇文章