s2.py
import tornado.ioloop import tornado.web text_list=[] class MainHandler(tornado.web.RequestHandler): def get(self): self.render('s2.html',xxoo=text_list) def post(self, *args, **kwargs): name= self.get_argument('tex') text_list.append(name) self.render('s2.html',xxoo=text_list) settings={ 'template_path':'tpl', 'static_path': 'static', } application = tornado.web.Application([ (r"/index", MainHandler), ],**settings) if __name__ == "__main__": application.listen(8888) tornado.ioloop.IOLoop.instance().start()
s2.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>提交内容</h1> <form method="post" action="/index"> <input type="text" name="tex"> <input type="submit" value="提交"> </form> <h1>展示内容</h1> <ul> {% for item in xxoo %} <li>{{item}}</li> {% end %} </ul> </body> </html>