web框架_Tornado_01

参考:http://demo.pythoner.com/itt2zh/index.html

环境:win10 + python3.6 + tornado

配置文件:config.py

#coding:utf-8

configs = {
    'port':8080,
    'param':['haha','gege'],
    'logging':None,
}

 

应用文件:debug.py

import tornado.web

class Index(tornado.web.RequestHandler):

    def get(self):
        return self.write('hello word!')

 

启动文件:server.py

import tornado.options
import tornado.web
import tornado.ioloop
import tornado.httpserver

import config
from debug import Index

#定义参数
tornado.options.define('port',default=8000,type=int,help='start port...')
tornado.options.define('param',default=[],type=list,help='params...')
tornado.options.options.logging = config.configs['logging']

#配置
tornado.options.options.port = config.configs['port']
tornado.options.options.param = config.configs['param']

#提交配置
tornado.options.parse_command_line()
print(tornado.options.options.port)
print(tornado.options.options.param)

#应用
app = tornado.web.Application([
    (r'/',Index),
])

#监听启动
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(tornado.options.options.port)
tornado.ioloop.IOLoop.current().start()

 

这样就可以启动一个简单的接口啦!

posted on 2017-07-08 11:09  hcguo  阅读(123)  评论(0编辑  收藏  举报