Categories
Python Answers

How to get POST and GET variables in Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *