Skip to content

Instantly share code, notes, and snippets.

@VictorZhang2014
Created October 15, 2019 13:11
Show Gist options
  • Save VictorZhang2014/2deeb3312fa72ebe73d111dad22cd0dd to your computer and use it in GitHub Desktop.
Save VictorZhang2014/2deeb3312fa72ebe73d111dad22cd0dd to your computer and use it in GitHub Desktop.
import tornado.ioloop
import tornado.web
import os
from tornado.options import define, options
define("port", default=8100, help="run on the given port", type=int)
class MainHandler(tornado.web.RequestHandler):
def get(self):
# The `index.html` is located in `templates` folder
self.render("index.html")
def make_app():
settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
)
return tornado.web.Application(
[(r"/", MainHandler)],
**settings
)
if __name__ == "__main__":
tornado.options.parse_command_line()
app = make_app()
http_server = tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment