import tornado.ioloop import tornado.web INPUT_LIST=[] class MainHandle(tornado.web.RequestHandler): def get(self): #self.write("Hello,world") self.render('s1.html',xxxooo=INPUT_LIST) def post(self, *args, **kwargs): name=self.get_argument('xxx') INPUT_LIST.append(name) self.render('s1.html',xxxooo=INPUT_LIST) settings={ "template_path" : "template", "static_path" : "static", } #路由映射,路由系统 application=tornado.web.Application([ (r"/index",MainHandle), ],**settings) if __name__=="__main__": application.listen(8000) tornado.ioloop.IOLoop.instance().start()

3.tornado框架
写:
-继承类
-application
-run
-配置文件
-模板路径
补充
self.get_argument("xxx") #获取用户提交数据
POST只能通过input提交
GET可以通过url传送给后台
模板预演:
{% for item in xxxooo %}
<li>{{item}}</li>
{% end %}
模板语言:
{{}}
{}
-uimethod
def func(self,arg): return arg.lower()
-uimodule
from tornado.web import UIModule from tornado import escape class custom(UIModule): def render(self, *args, **kwargs): return "1234"
import tornado.ioloop import uimethod as mt import uimodule as md import tornado.web INPUT_LIST=[] class MainHandle(tornado.web.RequestHandler): def get(self): #self.write("Hello,world") self.render('s1.html',nap="NMP888",xxxooo=INPUT_LIST) def post(self, *args, **kwargs): name=self.get_argument('xxx') INPUT_LIST.append(name) self.render('s1.html',xxxooo=INPUT_LIST) settings={ "template_path" : "template", "static_path" : "static", "ui_methods":mt, "ui_modules":md, } #路由映射,路由系统 application=tornado.web.Application([ (r"/index",MainHandle), ],**settings) if __name__=="__main__": application.listen(8000) tornado.ioloop.IOLoop.instance().start()
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <link rel="stylesheet" href='{{static_url("commons.css")}}'/> </head> <body> <h1>输入内容:</h1> <form method="post" action="/index"> <input type="text" name="xxx"> <input type="submit" value="提交"> </form> <h1>展示内容:</h1> <h3>{{ nap }}</h3> <h3>{{ func(nap) }}</h3> <h3>{% module custom() %}</h3> <ul> {% for temp in xxxooo %} <li>{{temp}}</li> {% end %} </ul> <script src={static_url("oldboy.js")}}'></script> </body> </html>
浙公网安备 33010602011771号