时间:2021-07-01 10:21:17 帮助过:93人阅读
def make_response(self, rv):
...
if not isinstance(rv, self.response_class):
if isinstance(rv, (text_type, bytes, bytearray)):
rv = self.response_class(rv, headers=headers, status=status)
headers = status = None
# rv是 method handle返回的结果,在k神代码中是
else:
rv = self.response_class.force_type(rv, request.environ)
因为type(data)返回的是一个type类型,而函数不允许return一个type类型。改成这样:def safestr(obj, encoding='utf-8'):
r"""
Converts any given object to utf-8 encoded string.
>>> safestr('hello')
'hello'
>>> safestr(u'\u1234')
'\xe1\x88\xb4'
>>> safestr(2)
'2'
"""
if isinstance(obj, unicode):
return obj.encode(encoding)
elif isinstance(obj, str):
return obj
elif hasattr(obj, 'next'): # iterator
return itertools.imap(safestr, obj)
else:
return str(obj)
我写的flask应用中,methods是写在app.route装饰器里面的。