我使用的瓶上的Python 2.7,我想返回一個值作爲JSON值,我試圖做到這一點,因爲這,Python'dict'對象不可調用?
user_id = 100
return_id = {}
return_id['user'] = user_id
return return_id
但是我發現了以下錯誤,
下面是完整的回溯,
127.0.0.1 - - [03/Oct/2016 15:04:16] "POST /add_new_patient HTTP/1.1" 500 - 127.0.0.1 - - [03/Oct/2016 15:04:30] "OPTIONS /add_new_patient HTTP/1.1" 200 - [2016-10-03 15:04:30,199] ERROR in app: Exception on /add_new_patient [POST] Traceback (most recent call last): File "/mnt/663E60F33E60BE25/Users/acer/Documents/code/thalback/venv/local/lib/python2.7/site-packages/flask/app.py", line 1988, in wsgi_app response = self.full_dispatch_request() File "/mnt/663E60F33E60BE25/Users/acer/Documents/code/thalback/venv/local/lib/python2.7/site-packages/flask/app.py", line 1642, in full_dispatch_request response = self.make_response(rv) File "/mnt/663E60F33E60BE25/Users/acer/Documents/code/thalback/venv/local/lib/python2.7/site-packages/flask/app.py", line 1746, in make_response rv = self.response_class.force_type(rv, request.environ) File "/mnt/663E60F33E60BE25/Users/acer/Documents/code/thalback/venv/local/lib/python2.7/site-packages/werkzeug/wrappers.py", line 847, in force_type response = BaseResponse(*_run_wsgi_app(response, environ)) File "/mnt/663E60F33E60BE25/Users/acer/Documents/code/thalback/venv/local/lib/python2.7/site-packages/werkzeug/test.py", line 871, in run_wsgi_app app_rv = app(environ, start_response) TypeError: 'dict' object is not callable
該代碼沒有任何問題。你能爲你的問題添加更多的細節嗎? –
我試過你的代碼,它完美的作品。你的代碼中有沒有其他地方可以稱爲字典? – MMF
做json.dumps()如果它是ajax調用。 –