tornado中通用模版

第一:

1.Pycharm新建python项目(不是django项目),在项目下面直接新建server.py,内容如下:

2.安装tornado, pip install tornado

import tornado.web
import tornado.ioloop
import tornado.httpserver
import config

class Indexhandler(tornado.web.RequestHandler):
    def get(self,*args,**kwargs):
        self.write("good is luck")


if __name__=="__main__":
    app = tornado.web.Application([
        (r'/',Indexhandler)
    ])

    httpserver=tornado.httpserver.HTTPServer(app)
    httpserver.bind(config.options["port"])
    httpserver.start(1)
    tornado.ioloop.IOLoop.current().start()

第二:在项目下面新建一个配置文件config.py

options = {
    "port":9000
}

通过以上通用模版,可以改为跟django类似的项目结构,具体如下:

原文地址:https://www.cnblogs.com/weilaibuxiangshuo/p/11016171.html