查看装饰器的代码:
def login_required(handler_method):
"""..."""
def check_login(self, *args):
if self.request.method != 'GET':
raise webapp.Error('The check_login decorator can only be used for GET '
'requests')
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url(self.request.uri))
return
else:
handler_method(self, *args)
return check_login
如果用户成功登录,则无法运行其他代码。
你可以编写一个自定义版本的装饰器来做你想做的事情:
def custom_login_required(handler_method):
"""..."""
def check_login(self, *args):
if self.request.method != 'GET':
raise webapp.Error('The check_login decorator can only be used for GET '
'requests')
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url(self.request.uri))
return
else:
users = UserModel.query(UsersModel.email == users.get_current_user().email()).fetch()
if len(users) == 0:
user = UsersModel(email = users.get_current_user().email())
user.put()
handler_method(self, *args)
return check_login