老男孩的替身

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
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>

 

posted on 2018-06-03 18:58  贾老板  阅读(92)  评论(0)    收藏  举报