which is better ?
app.py
#!/usr/bin/env python
#coding=utf-8
import tornado.web
import tornado.ioloop
import tornado.autoreload
from controllers import Users
App = tornado.web.Application
Asynchronous= tornado.web.asynchronous
Server = tornado.ioloop.IOLoop.instance()
app = App([
(r'/user/login', Users.login ),
])
app.listen(8888)
tornado.autoreload.start(Server)
Server.start()
Users.py (in controllers)
#!/usr/bin/env python
#coding=utf-8
import tornado.web
from baseController import BaseController
from models import user
class login(BaseController):
@tornado.web.asynchronous
def post(self):
users = user.User() # is use like this OK ?
users.login(self.response)
def response(self, ret):
self.finish(ret)
user.py ( in models)
#!/usr/bin/env python
#coding=utf-8
import copy
from baseModle import BaseModle
class User(BaseModle):
def login(self, callback):
data = do something
callback(data)
Users.py (in controllers) v2
#!/usr/bin/env python
#coding=utf-8
import tornado.web
from baseController import BaseController
from models import user
users = user.User()
class login(BaseController):
@tornado.web.asynchronous
def post(self):
users.login(self.response)
def response(self, ret):
self.finish(ret)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上方那个方案更好。