我在几个项目中都使用过烧瓶,但在创建restul时从未使用过烧瓶--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')是什么导致了这一切?不管我做什么,错误依然存在。看着url_map从酒瓶,我可以看到我的路线在那里-它看起来很好。当离开蓝图并将其保存在一个文件中时,它可以工作。Pythonv2.7和烧瓶-RESTfulv0.2.12(安装在Ubuntu的pip上)。
发布于 2021-09-22 07:34:31
这对我起了作用:
在您的环境中添加ERROR_404_HELP=False:
app.config['ERROR_404_HELP'] = False发布于 2019-01-25 11:20:49
我有类似的问题与尾随斜杠有关,例如,我定义了api.com/终结点,并向api.com/终结点/发送请求,并且有404个错误。
解决方案是通过:app.url_map.strict_slashes = False将Flask应用程序配置为不严格地尾随斜杠
https://stackoverflow.com/questions/25765052
复制相似问题