因此,按照swagger ui使用flask blueprints (https://github.com/rantav/flask-restful-swagger/blob/master/examples/blueprints.py)的示例,我有以下代码:
app = Flask(__name__)
test_blueprint = Blueprint('tests', __name__)
test_api = swagger.docs(restful.Api(test_blueprint), apiVersion='0.1',
basePath='http://localhost:5000',
produces=["application/json", "text/html"],
api_spec_url='/api/spec')
# Operation TestOp defined here
test_api.add_resource(TestOp, '/')
if __name__ == "__main__":
app.register_blueprint(test_blueprint, url_prefix='/test')
app.run(debug=True)但是,当我尝试访问api规范文档时,无法找到URL。我试过..。
localhost:5000/api/spec
localhost:5000/test_api/api/spec
localhost:5000/test_api其中的...all返回404。我还尝试过在没有蓝图的情况下创建应用程序,使用
swagger.docs(restful.Api(app)...)而不是。当这项工作完成并且不涉及蓝图时,我可以在以下位置找到文档
localhost:5000/api/spec那么,我是不是用蓝图错误地创建了我的应用程序,或者我只是没有找到正确的URL来访问文档?
发布于 2014-08-27 23:54:17
看起来你只是没有找到正确的URL。因为您的蓝图url_prefix是"/test",所以Swagger规范的url应该是:
localhost:5000/test/api/spec发布于 2016-10-13 23:37:14
我知道这个帖子很老了,但是我今天遇到了这个问题,我试着把flask-restful-swagger和我(有点)使用蓝图的现代flask + python3应用程序一起使用。同样的问题,没有错误,只是无论我尝试了什么,都没有可用的规范。
我最终放弃了这个包(因为它看起来并不是很活跃),尽管我更喜欢这个包的标记。
我选择了Flasgger,它似乎是最近更新的。在10分钟内,我就把它启动并运行起来。代码和简短教程在这里:https://github.com/rochacbruno/flasgger
发布于 2019-02-27 14:20:43
swagger.docs()中的一些错误
from flask_restful import Api
test_blueprint = Blueprint('tests', __name__)
test_api = swagger.docs(Api(test_blueprint)...)
app.register_blueprint(test_blueprint)更重要的是
main_blueprint = Blueprint('api', __name__, url_prefix='/demo')https://stackoverflow.com/questions/25477430
复制相似问题