Skip to content

Instantly share code, notes, and snippets.

@xhiroga
Last active October 2, 2017 23:07
Show Gist options
  • Save xhiroga/9402aa3ee0a19fb7be74b6b7cbdc0a07 to your computer and use it in GitHub Desktop.
Save xhiroga/9402aa3ee0a19fb7be74b6b7cbdc0a07 to your computer and use it in GitHub Desktop.
PRG Pattern sample for me
import tornado.ioloop
import tornado.web
from jinja2 import Environment, FileSystemLoader
class MainHandler(tornado.web.RequestHandler):
def get(self):
env = Environment(loader=FileSystemLoader('./', encoding='utf8'))
template = env.get_template('./login.html')
self.write(template.render())
class RegisterHandler(tornado.web.RequestHandler):
def post(self):
# 登録処理
self.redirect(r"/thanks")
class ThanksHandler(tornado.web.RequestHandler):
def get(self):
self.write("Thanks!!")
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
(r"/register", RegisterHandler),
(r"/thanks", ThanksHandler),
])
if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment