*this question is not a duplicate of another question and I have already tried the answer given in that question and it did not solve my problem. Thanks.Python SQLalchemy TypeError: 'list'オブジェクトは呼び出し可能ではありません
私はPythonの初心者で、SQLalchemyの使い方を学んでいます。
- 私は私のJSコードは、オブジェクトのリストを読んで、ビューに表示されます
- オブジェクトのリストとして結果を返す私のデータベーステーブル
- からすべての行を取得しようとしています
しかし、私はこのリストオブジェクトを取得している呼び出し可能なエラーではありません。誰かが私にこのガイドを与えることができますあなたに感謝してください。
@mod_core.route('/getDatatable', methods=['GET'])
def datatable_get():
# Query 'user' table.
_user = User.query.all()
_results = []
for user in _user:
print user.get_all()
_results.append(user.get_all())
return _results
127.0.0.1 - - [22/Jan/2017 17:10:46] "GET /getDatatable HTTP/1.1" 500 - Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 2000, in call return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1991, in wsgi_app response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask_restful/init.py", line 271, in error_router return original_handler(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1567, in handle_exception reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1988, in wsgi_app response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1642, in full_dispatch_request response = self.make_response(rv)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1746, in make_response rv = self.response_class.force_type(rv, request.environ)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 847, in force_type response = BaseResponse(*_run_wsgi_app(response, environ))
File "/usr/local/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 57, in _run_wsgi_app return _run_wsgi_app(*args)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/test.py", line 871, in run_wsgi_app app_rv = app(environ, start_response)
TypeError: 'list' object is not callable
UPDATE 1:私も、返す前にJSONにユーザーを変更しようとしたし、まだ同じエラーを取得しています
@mod_core.route('/getDatatable', methods=['GET'])
def datatable_get():
# Query 'user' table.
_user = User.query.all()
results = []
for user in _user:
results.append(user.to_json())
print results
return results
Userクラス
def to_json(self):
"""
Return a JSON response for RESTful API GET request.
"""
_user_in_josn = {'login_id': self.login_id,
'fullname': self.fullname,
'nickname': self.nickname,
'matric': self.matric_no,
'email': self.email,
'alt_email': self.alt_email
}
return _user_in_josn
UPDATE 2:JSONにキャストしようとしました戻っ結果
User object at 0x7f88f80b14d0> is not JSON serializable
前は私を沿って案内してください。あなたの親切な注意と助けをありがとう。
スタックトレースは、ハイテクお返事に感謝を – schematic