1

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.

Duncan Marshall
  • 530
  • 1
  • 6
  • 15
  • *How* are you using Apache2? How are you serving your app? Python is not a web-specific language like PHP, it needs some interface with Apache. What are you using (and why didn't you look in the documentation for that library?) – Daniel Roseman Feb 18 '14 at 10:29
  • I'm not aware of any specific library that I'm using. I'm not importing anything. The code is literally as minimal as it looks above. – Duncan Marshall Feb 18 '14 at 10:33
  • @DuncanMarshall Then try `import os` and `print(os.environ())` and see if what you're looking for is in there. perhaps even `sys.argv` can assist you. – Torxed Feb 18 '14 at 10:43
  • Python is not PHP, and it doesn't work the same way. – Burhan Khalid Feb 18 '14 at 10:49
  • 1
    @BurhanKhalid Yup. Hence the question. – Duncan Marshall Feb 18 '14 at 10:55

1 Answers1

3

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')
curiousguy
  • 3,212
  • 8
  • 39
  • 71