title: View rendering decorator for JSON with GAE in Flask
body: <p>I'm trying to write a view rendering decorator for JSON in Flask following this snippet: <a href="http://flask.pocoo.org/snippets/18/" rel="nofollow">http://flask.pocoo.org/snippets/18/</a></p>
  
  <p>The thing is that I need to serialize as JSON, GAE models, for which the <em>jsonify</em> function does not work. For this I'm using the following code: <a href="http://blog.worldmaker.net/2009/dec/08/simple-app-engine-json-serialization-snippet/" rel="nofollow">http://blog.worldmaker.net/2009/dec/08/simple-app-engine-json-serialization-snippet/</a></p>
  
  <p>Similar to the render_html example in the snippet above, I wrote the following code:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>The problem is that I invoke a function decorated with my new decorator, I get the following error:</p>
  
  <pre><code>AttributeError: 'Response' object has no attribute 'next'
  </code></pre>
  
  <p>Can anyone point out what is going on here?
  Thanks!</p>
  
  <p>Marcos</p>
  
  <p>EDIT: Here is the traceback</p>
  
  <pre><code>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())
  </code></pre>