【发布时间】:2014-11-04 01:56:13
【问题描述】:
我在几个项目中使用过 Flask,但在创建 restul API 时从未使用过 flask-restful 包 - 所以我想我应该试一试。
但是,我遇到了一个我无法理解的奇怪错误 - 并且 API 根本不起作用。错误消息说
{
"message": "Not Found. You have requested this URI [/api/v1.0/items] but did you mean /api/v1.0/items ?",
"status": 404
}
run.py
from my_project import app
if __name__ == '__main__':
app.run(host=0.0.0.0, debug=app.config['DEBUG'])
my_project/_ init _.py
from flask import Flask
app = Flask(__name__)
from my_project.base import blueprint as BaseBluePrint
from my_project.api import blueprint as ApiBluePrint
app.register_blueprint(BaseBluePrint)
app.register_blueprint(ApiBluePrint, url_prefix='/api/v1.0')
my_project/api/_ init _.py
from flask import Blueprint
from flask.ext import restful
blueprint = Blueprint('api', __name__)
api = restful.Api(blueprint)
class ItemList(restful.Resource):
def get(self):
return false
api.add_resource(ItemList, '/items', endpoint='items')
是什么原因造成的?无论我做什么,错误仍然存在。看着来自 Flask 的url_map,我可以看到我的路线 - 它看起来不错。当远离蓝图并将其全部保存在一个文件中时,它可以工作。 Python v2.7 和 flask-restful v0.2.12(从 Ubuntu Precise 上的 pip 安装)。
【问题讨论】:
-
唯一想到的是某个地方的隐藏字符,无论是在您的请求中,还是在您设置的端点中。尝试重新输入所有内容 - 如果没有,请在此处打开一个问题:github.com/twilio/flask-restful
-
试试
return False
标签: python flask flask-restful