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!