我目前有一个授权标头:
def authorize(allowed_groups=None, debug=False):
# Do your auth here...
headers = cherrypy.request.headers
return
if 'consumer_key' in headers:
if check_consumer_key(headers['consumer_key']):
if 'access_token' in headers:
cherryPy.accept = check_access_token['access_token']
else:
cherrypy.accept = False
我在这里使用它:
@cherrypy.tools.authorize()
def GET(self, id=None):
#return the order list for this account type
if cherrypy.accept:
print "Accepted"
user = User()
usermodel = user.get_all()
return json.dumps(usermodel, cls=AlchemyEncoder)
所以,与其做一个 cherrpy.accept = True,当授权不正确时,如何在装饰器本身中返回一个错误页面?