【问题标题】:python flask URL error: 'The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.'python烧瓶URL错误:'在服务器上找不到请求的URL。如果您手动输入了 URL,请检查您的拼写并重试。
【发布时间】:2020-07-12 16:48:15
【问题描述】:

当我尝试应用 url 路由时,我收到了这个错误。 代码如下:

from flask import Flask
from flask_restplus import Resource, Api

app = Flask(__name__)
api = Api(app)

@api.route('/GET/collections/<id>/<year>?q=<query>')
class DataRetrive(Resource):
    def get(self,id, year, query):
        return 'yes'

if __name__ == '__main__':
    app.run(debug=True)

【问题讨论】:

    标签: python flask


    【解决方案1】:

    我认为您不需要指定查询参数“q”

    试试这样的:

    from flask import Flask, request
    from flask_restplus import Resource, Api
    
    app = Flask(__name__)
    api = Api(app)
    
    @api.route('/GET/collections/<id>/<year>')
    class DataRetrive(Resource):
        def get(self,id, year):
            q = request.args.get('q')
            return 'yes'
    
    if __name__ == '__main__':
        app.run(debug=True)
    
    

    注意没有定义的国家参数...

    所以你的网址看起来像这样:

    localhost:5000/GET/collections/1/2020?q=something

    【讨论】:

      猜你喜欢
      • 2020-10-03
      • 2023-03-25
      • 2021-06-16
      • 2020-06-19
      • 2020-12-03
      • 2020-04-29
      • 1970-01-01
      • 2014-04-17
      • 1970-01-01
      相关资源
      最近更新 更多