【tornado建站】前端与后端基础模块准备
先测试tornado是否可用,首先随手写一个index.html
<p>这是测试</p>
然后tornado的测试代码website.py如下:
import tornado.ioloop
import tornado.web
from tornado.options import define, options
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", IndexHandler),
]
settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
debug=True,
)
tornado.web.Application.__init__(self, handlers, **settings)
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html')
def main():
define("port", default=8000, help="run on the given port", type=int)
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(Application())
htt