1

我第一次将 SQLite 与 Flask 一起使用,并尝试检索我刚刚插入数据库的数据。我将 JSON 数据插入数据库的 POST 请求工作正常(或至少不返回错误)。

我正在尝试显示我插入的任何内容以进行验证并按如下方式进行操作:

cur = db.execute('select * from places order by id')
entries = [dict(lat=row[0], long=row[1], address=row[2], name=row[3]) for row in cur.fetchall()]
return entries

我收到错误 500。为什么会这样?我只能找到两个做的例子,他们都在做我上面所说的。

编辑:

这是烧瓶的错误:

Traceback (most recent call last):
  File "/Users/nayef/.virtualenvs/uber-api/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/nayef/.virtualenvs/uber-api/lib/python2.7/site-packages/flask/app.py", line 1689, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Users/nayef/.virtualenvs/uber-api/lib/python2.7/site-packages/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/nayef/.virtualenvs/uber-api/lib/python2.7/site-packages/flask/app.py", line 1361, in full_dispatch_request
    response = self.make_response(rv)
  File "/Users/nayef/.virtualenvs/uber-api/lib/python2.7/site-packages/flask/app.py", line 1450, in make_response
    rv = self.response_class.force_type(rv, request.environ)
  File "/Users/nayef/.virtualenvs/uber-api/lib/python2.7/site-packages/werkzeug/wrappers.py", line 711, in force_type
    response = BaseResponse(*_run_wsgi_app(response, environ))
  File "/Users/nayef/.virtualenvs/uber-api/lib/python2.7/site-packages/werkzeug/wrappers.py", line 55, in _run_wsgi_app
    return _run_wsgi_app(*args)
  File "/Users/nayef/.virtualenvs/uber-api/lib/python2.7/site-packages/werkzeug/test.py", line 818, in run_wsgi_app
    app_iter = app(environ, start_response)
TypeError: 'list' object is not callable
4

1 回答 1

0

尝试返回return repr(entries)。您的视图应该返回字符串而不是列表对象。无论出于何种原因,如果你返回一个列表,flask 会尝试调用它,你会得到一个TypeError: 'list' object is not callable错误。

于 2012-11-09T04:49:14.933 回答