我正在尝试按照以下片段在 Flask 中为 JSON 编写视图渲染装饰器:http: //flask.pocoo.org/snippets/18/
问题是我需要序列化为 JSON、GAE 模型,而jsonify函数对此不起作用。为此,我使用以下代码:http ://blog.worldmaker.net/2009/dec/08/simple-app-engine-json-serialization-snippet/
与上面代码片段中的 render_html 示例类似,我编写了以下代码:
def render_json(result):
def wrapped(*args, **kwargs):
json_string = json.dumps(result, cls=GaeEncoder)
return app.response_class(response=json_string, mimetype='application/json')
return wrapped
问题是我调用了一个用我的新装饰器装饰的函数,我收到以下错误:
AttributeError: 'Response' object has no attribute 'next'
谁能指出这里发生了什么?谢谢!
马科斯
编辑:这是回溯
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 208, in Handle
for chunk in result:
File "/Users/mchicote/Documents/projects/schoolnetwork/code/SchoolNetwork/sn/../lib/flaskext/gae_mini_profiler/profiler.py", line 286, in __call__
yield self.prof.runcall(result.next)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/cProfile.py", line 149, in runcall
return func(*args, **kw)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/appstats/recording.py", line 1284, in appstats_wsgi_wrapper
result = app(environ, appstats_start_response)
File "/Users/mchicote/Documents/projects/schoolnetwork/code/SchoolNetwork/sn/../lib/flaskext/gae_mini_profiler/profiler.py", line 269, in wrapped_appstats_app
return old_app(environ, start_response)
File "/Users/mchicote/Documents/projects/schoolnetwork/code/SchoolNetwork/sn/../lib/flask/app.py", line 1689, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/mchicote/Documents/projects/schoolnetwork/code/SchoolNetwork/sn/../lib/flask/app.py", line 1687, in wsgi_app
response = self.full_dispatch_request()
File "/Users/mchicote/Documents/projects/schoolnetwork/code/SchoolNetwork/sn/../lib/flask/app.py", line 1361, in full_dispatch_request
response = self.make_response(rv)
File "/Users/mchicote/Documents/projects/schoolnetwork/code/SchoolNetwork/sn/../lib/flask/app.py", line 1450, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/Users/mchicote/Documents/projects/schoolnetwork/code/SchoolNetwork/sn/../lib/werkzeug/wrappers.py", line 711, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/Users/mchicote/Documents/projects/schoolnetwork/code/SchoolNetwork/sn/../lib/werkzeug/wrappers.py", line 55, in _run_wsgi_app
return _run_wsgi_app(*args)
File "/Users/mchicote/Documents/projects/schoolnetwork/code/SchoolNetwork/sn/../lib/werkzeug/test.py", line 836, in run_wsgi_app
buffer.append(app_iter.next())