Sometimes, we want to get POST and GET variables in Python.
In this article, we’ll look at how to get POST and GET variables in Python.
How to get POST and GET variables in Python?
To get POST and GET variables in Python, we can use the cgi
library.
For instance, we write
import cgi
form = cgi.FieldStorage()
print(form["username"])
to get the form field values with
cgi.FieldStorage()
in a dict.
Then we get the value of the form data with field name username
with
form["username"]
It should be set when we submit a value from an input like
<input type="text" name="username">
Conclusion
To get POST and GET variables in Python, we can use the cgi
library.