## 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]