Search code examples
pythonflaskmarshmallow

How to load query string arguments in Flask Marshmallow schema


I have a POST request defined in my Flask app as below:

https://www.foo.com/<foo_id>?bar_id=3

I am getting the path parameter foo_id as below:

from flask_restplus import Namespace, Resource

ns = Namespace('Foo API')

@ns.route("/<string:foo_id>")
class FooExecute(Resource):

    def get(self, foo_id):
        print('foo_id = {}'.format(foo_id))

Though I am not able to get the query paramater bar_id. What is the right way to retrieve it?


Solution

  • You can try using the Request class within Flask to get the params as follows:

    from flask import request
    
    request.args.get('bar_id')