代码:路径:1/2/3/.py
import os.path
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.options
from tornado.options import define,optionsdefine('port',default=8001,help='运行在指定端口',type=int)
class IndexHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html')class poempagehandler(tornado.web.RequestHandler):
def post(self):
n1=self.get_argument('n1')
n2=self.get_argument('n2')
verb=self.get_argument('verb')
n3=self.get_argument('n3')
self.render('poem.html',roads=n1,wood=n2,made=verb,difference=n3)if __name__=='__main__':
tornado.options.parse_command_line()
app=tornado.web.Application([(r'/',IndexHandler),(r'/poem',poempagehandler)],template_path=os.path.join(os.path.dirname(__file__),'templates'))
http_server=tornado.httpserver.HTTPServer(app)
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
index.html代码:路径1/2/3templates/index.html
<!DOCTYPE html>
<html>
<head><title>会员登陆</title></head>
<body>
<h1>输入注册信息</h1>
<form method='post' action='/poem'>
<p>用户名<br><input type='text' name='n1'></p>
<p>密码<br><input type='text' name='n2'></p>
<p>确认密码<br><input type='text' name='verb'></p>
<p>性别<br><input type='text' name='n3'></p>
<input type='submit'>
</form>
</body>
</html>
poem.html代码如下:路径:1/2/3/templates/poem.html
<!DOCTYPE html>
<html>
<head><title>注册结果</title></head>
<body>
<h1>下面是你的注册信息</h1>
<p>用户名:{{roads}}<br>密码:{{wood}}<br>确认密码:{{made}}<br>性别:{{difference}}.</p>
</body>
</html>
结果如下: