tornado基础知识想必大家已经学的差不多了。接下来小编会为大家带来稍微有点难度的知识点。看不懂的可以多学几遍。
众所周知,网站是一个极其复杂的系统,不可能只有一个静态页面。所以我们将上文的代码做一下改变:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | 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是你网页模板所需的css,js,图片等存放的地方
以上就是python tornado更改代码的方法。更多Python学习推荐:PyThon学习网教学中心。