Is there a Python equivalent of PHP's $_GET[] and $_POST[]?

0

Issue

I’m using python and apache2.

I’d like to write a script called test.py that when accessed at http://example.com/test.py?foo=bar, prints the string ‘bar’

I’m thinking it should be like this:

def index(req):

    return idontknow.foo

The idontknow.foo is the part I’m asking about.

Solution

You can use fieldstorage in cgi for ex :

if the url is :

hello_get.py?first_name=ABC&last_name=XYZ

#!/usr/bin/python

# Import modules for CGI handling 
import cgi, cgitb 

# Create instance of FieldStorage 
form = cgi.FieldStorage() 

# Get data from fields
first_name = form.getvalue('first_name')
last_name  = form.getvalue('last_name')

Answered By – curiousguy

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More