https://github.com/JackLiu16/callback
注入实例
#conding=utf-8
class FlaskLocalStack(object):
local = None
class LoginManager(object):
def __init__(self):
# print "in __init__"
pass
def init_app(self, app):
# print id(self)
app.local = self
def login(self):
print "login successful"
lg = LoginManager()
ll = FlaskLocalStack()
lg.init_app(ll)
ll.local.login()
回调传递方法
class LoginManager(object):
def __init__(self):
pass
def user_loader(self, callback):
self.user_callback = callback
return callback
import login_manager
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
运行上下文中login_manager单例