有时候做一些简单的前端学习的时候可能需要表单来配合ajax和后台交互的模拟。

python版本 2.7.5

tornado版本 3.0.1

so: win7

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#hello_get_post.py tornadohelloworld案例  orangleliu@2014.03.02
#这里是一个简单的页面,get一个表单页面,使用post处理请求,没有使用模板就是
#直接用字符拼出来的html

import tornado.ioloop 
import tornado.web 

#handler request请求
class MainHandler(tornado.web.RequestHandler):
		def get(self):
				self.write('<html><body>'+
					'<form action="/" method="post">'+
					'<input type="text" name="message">'+
					'<input type="submit" value"提交">'+
					'</form>'+
					'</body></html>')

		def post(self):
				#获取参数
				message = self.get_argument("message", None)
				self.write('Form input is :<h1>'+message+'</h1>')


#url router
application = tornado.web.Application([
		(r'/', MainHandler),		
])


#web server
if __name__=='__main__':
		application.listen(8888)
		tornado.ioloop.IOLoop.instance().start()



Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐