Simple Forms and templates:
1 ImportOs.path2 3 ImportTornado.httpserver4 ImportTornado.ioloop5 Importtornado.options6 ImportTornado.web7 8 fromTornado.optionsImportDefine, Options9Define"Port", default=8000, help="run on the given port", type=int)Ten One classIndexhandler (tornado.web.RequestHandler): A defGet (self): -Self.render ('index.html') - the classPoempagehandler (tornado.web.RequestHandler): - defpost (self): -NOUN1 = Self.get_argument ('noun1') -Noun2 = Self.get_argument ('noun2') +verb = self.get_argument ('verb') -Noun3 = Self.get_argument ('Noun3') +Self.render ('poem.html', Roads=noun1, Wood=noun2, made=verb, ADifference=noun3) at - if __name__=='__main__': - Tornado.options.parse_command_line () -App =Tornado.web.Application ( -Handlers=[(R'/', Indexhandler), (R'/poem', Poempagehandler)], -Template_path=os.path.join (Os.path.dirname (__file__),"Templates") in ) -Http_server =tornado.httpserver.HTTPServer (APP) to Http_server.listen (Options.port) +Tornado.ioloop.IOLoop.instance (). Start ()
poemmaker.py
Enter the page:
1<! DOCTYPE html>234<body>56<form method="Post"action="/poem">7<p>plural Noun<br><input type="text"Name="noun1"></p>8<p>singular Noun<br><input type="text"Name="noun2"></p>9<p>verb (past tense) <br><input type="text"Name="verb"></p>Ten<p>noun<br><input type="text"Name="Noun3"></p> One<input type="Submit"> A</form> -</body> -index.htmlOutput page:
1 <! DOCTYPE html> 2 3 4 <body> 5 6 in and i-<br> 7 I took the one less travelled by,<br> 8 and that have {{made}} all the {{differe} Nce}}.</p> 9 </body>
poem.htmlLogin in Python Get data jump page (without database)