简体   繁体   English

Python(Flask + Swagger)Flasgger抛出404错误

[英]Python (Flask + Swagger) Flasgger throwing 404 error

I am trying to use swagger ui as a frontend to query my flask application. 我正在尝试使用swagger ui作为前端来查询我的flask应用程序。 I'm using Flasgger I tried a toy example as shown below 我正在使用Flasgger我尝试了一个玩具示例,如下所示

from flasgger import Swagger
from flask import Flask, logging

app = Flask(__name__)
Swagger(app)


# ENDPOINT = 1
@app.route('/hello',methods=['GET'])
def helloapp():
    return 'Hello World'

if __name__ == '__main__':
    app.run(debug=True,threaded=True,port=7005)
    file_handler = logging.FileHandler('app.log')
    app.logger.addHandler(file_handler)
    app.logger.setLevel(logging.INFO)

When i try to query the endpoint http://localhost:7005/hello . 当我尝试查询端点http://localhost:7005/hello I get the result with 'Hello World'. 我通过“ Hello World”获得结果。

If I try to query http://localhost:7005/apidocs/ This shows me the base UI 如果我尝试查询http://localhost:7005/apidocs/这将向我显示基本UI 在此处输入图片说明


But, when I try to query the endpoint root. 但是,当我尝试查询端点根时。 The swagger UI does not show up. 摇摇欲坠的用户界面不显示。 It throws me a 404 Error 它抛出404错误

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

Any pointers as to what is the issue ?. 关于什么是问题的任何指针?

Try to add the endpoint root to your routes like this: 尝试将端点根添加到您的路由中,如下所示:

@app.route('/')

@app.route('/hello',methods=['GET'])
# ... 

Because you didn't define it as a route, it cannot be found on the server. 由于您没有将其定义为路由,因此无法在服务器上找到它。 I hope that this will help you 希望对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM