import tornado.httpserver
import tornado.options
import tornado.ioloop
from tornado.options import define,options
define("port",type=int,default=9000)
#視圖
class Indexhandler(tornado.web.RequestHandler):
def get(self, *args, **kwargs):
self.write("<h1>Hello World</h1")
#url
urls=[
(r'/',Indexhandler)
]
#配置
configs=dict(
debug=True
)
class CustomApplication(tornado.web.Application):
def __init__(self,configs,urls):
handlers=urls
settings=configs
super(CustomApplication,self).__init__(handlers=handlers,**settings)
def create_app():
tornado.options.parse_command_line()
http_server=tornado.httpserver.HTTPServer(CustomApplication(configs,urls))
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
app=create_app()
if __name__ == "__main__":
app()