{% from util.module_file import sub,upper,Count %}
可以从其他文件夹直接导入模板
 
## 06ui.py
#coding:utf-8
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web

from  tornado.options import define,options

define('port',default=8000,help='run port',type=int)
define('version',default='0.0.1',help='version 0.0.1',type=str)


class Calculation():
    def sum(self, a, b):
        return a + b

class UiHandler(tornado.web.RequestHandler):

    def func(self):
        return 'nanian'
    def get(self):
        username=self.get_argument('name','no')
        self.render('07module.html',
                    username=username,
                    fun=self.func,
                    calc=Calculation

                    )


if __name__ == "__main__":
    tornado.options.parse_command_line()
    # print(options.port)
    app=tornado.web.Application(
        handlers=[
            (r'/ui',UiHandler),
        ],
        template_path='templates',
        static_path='static',
        debug=True,
        #autoescape=None,   #关闭自动转义 全局的
    )
 #固定写法:
    http_server=tornado.httpserver.HTTPServer(app)
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()


##  ./util/module_file.py
def sub(a,b):
    return a-b
def upper(a):
    return str(a).upper()

class Count():
    @classmethod
    def sum(cls,a,b):
        return a+b
    @property
    def url(self):
        return "<a href='www.baidu.com'>百度</a>"
    def args(self,*arg):
        return [str(a)+'--hehe' for a in args]
View Code

相关文章:

  • 2021-06-29
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2021-11-16
  • 2021-10-28
  • 2022-12-23
猜你喜欢
  • 2021-04-18
  • 2021-12-07
  • 2022-02-14
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案