• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python tornado如何更改代码?

python 搞java代码 3年前 (2022-05-21) 21次浏览 已收录 0个评论

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是你网页模板所需的cssjs,图片等存放的地方

以上就是python tornado更改代码的方法。更多Python学习推荐:云海天Python教程网

来源:搞代码网:原文地址:https://www.gaodaima.com


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python tornado如何更改代码?
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址