python – In Flask, what is request.args and how is it used?
python – In Flask, what is request.args and how is it used?
According to the flask.Request.args
documents.
flask.Request.args
A MultiDict with the parsed contents of the query string. (The part in the URL after the question mark).
So the args.get()
is method get()
for MultiDict
, whose prototype is as follows:
get(key, default=None, type=None)
In newer version of flask (v1.0.x and v1.1.x), flask.Request.args
is an ImmutableMultiDict
(an immutable MultiDict
), so the prototype and specific method above are still valid.
As a newbie using Flask and Python myself, I think some of the other answers here take for granted that you have a good understanding of the fundamentals. In case you or other readers dont, Ill give more context
… request.args
returns a dictionary object for you. The dictionary object is similar to other collection-type of objects in Python, in that it can store many elements in one single object. Therefore the answer to your question
And how many parameters
request.args.get()
takes.
It will take only one object, a dictionary type of object (as stated in the previous answers). This dictionary object, however, can have as many elements as needed… (dictionaries have paired elements called Key, Value).
Other collection-type of objects besides dictionaries, would be tuple, and list… you can run a google search on those and data structures in order to learn other Python fundamentals. This answer is based Python; I dont have an idea if the same applies to other programming languages.
python – In Flask, what is request.args and how is it used?
request.args
is a MultiDict with the parsed contents of the query string.
From the documentation of get
method:
get(key, default=None, type=None)
Return the default value if the
requested data doesn’t exist. If type is provided and is a callable it
should convert the value, return it or raise a ValueError if that is
not possible.
Related posts on python :
- python – Resize PyTorch Tensor
- bash – Fast ping sweep in python
- python – Import GoogleNews-vectors-negative300.bin
- python – Object does not support item assignment error
- How do I plot a step function with Matplotlib in Python?
- python – ImportError: No module named model_selection
- How do I plot a step function with Matplotlib in Python?