The problem that the flask_restful reqparse.RequestParser () help parameter cannot take effect

when passing the help parameter to add_argument when using flask_restful parameter parsing, the help message will not appear if an error is reported. The code is as follows:

-sharp -*-coding:utf-8 -*-

from flask_restful import reqparse
from flask import Flask, jsonify

app = Flask(__name__)

@app.route("/")
def index():
    parser = reqparse.RequestParser()
    parser.add_argument("page", type=int, help="invalid argument")
    args = parser.parse_args()
    return jsonify(args), 200

if __name__ == "__main__":
    app.run(port=9000, debug=True)

when accessed via http://localhost:9000/?page=9.1, you expect to return a 400error of "invalid argument", but the actual result is to return the default" 400 Bad Request The browser (or proxy) sent a request that this server could not understand. " Error prompt.
ask: what is the problem? If the classes parsed by flask_restful parameters cannot be used alone, is there a better method or tool for parameter verification and transformation? Thank you!

Mar.28,2021

Hello, what you need to understand is when parameter parsing takes effect.
Please adjust according to the following code:

-sharp -*-coding:utf-8 -*-

from flask_restful import reqparse
from flask import Flask, jsonify

def parsers():
    parser = reqparse.RequestParser()
    parser.add_argument('page', type=int, help='invalid argument')
    return parser.parse_args()

app = Flask(__name__)

    
@app.route('/')
def index():
    args = parsers()
    return jsonify(args), 200

if __name__ == '__main__':
    app.run(port=9000, debug=True)
The parsing of the

parameter has already completed the mapping in the precompilation phase.
at the same time, the hybrid use of flask and flask-RESTful is not good.

Menu