【发布时间】:2017-04-10 16:13:59
【问题描述】:
我目前正在学习 Python (Flask),并想为 HelloWorld 设置一个小型 REST API。我选择 flask_restful 来实现 API,并在他们的网站上关注 tutorial。
问题是,PyCharm 告诉我 ImportError:
没有名为 flask_restful 的模块
虽然我在我的 VirtualEnvironment 中通过 project interpreter 实现了该库。
这是我的代码:
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
def get(self):
return {'hello': 'world'}
api.add_resource(HelloWorld, '/')
if __name__ == '__main__':
app.run(debug=True)
有人知道正确使用flask_restful的诀窍吗?
INFO 2016-11-26 13:25:04,657 admin_server.py:116] Starting admin server at: http://localhost:8000
ERROR 2016-11-26 13:25:07,163 wsgi.py:263]
Traceback (most recent call last):
File "/Users/GamerXX/Documents/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Users/GamerXX/Documents/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Users/GamerXX/Documents/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/Users/GamerXX/PycharmProjects/PartyMate/main.py", line 3, in <module>
from flask_restful import Resource, Api
ImportError: No module named flask_restful
INFO 2016-11-26 13:25:07,169 module.py:788] default: "GET / HTTP/1.1" 500 -
【问题讨论】:
标签: python rest google-app-engine flask flask-restful