I am new to Python and am trying to marry a Python module with a CGI interface. I understand a little of both but not how they work together. I created a class called Vehicle and (using IDLE) and am able to import it and set the year, make, and model of a vehicle. See below.
class Vehicle:
def __init__(self, iyear, imake, imodel):
self.year = iyear
self.make = imake
self.model = imodel
def getYear(self):
return self.year
def getMake(self):
return self.make
def getModel(self):
return self.model
Here is what I know how to do using IDLE:
>>> from mymodule import *
>>> mycar = Vehicle("1984", "Ford", "F-150")
>>>
>>> mycar.getYear()
'1984'
>>> mycar.getMake()
'Ford'
>>> mycar.getModel()
'F-150'
>>>
My question is how can I use a cgi interface to set the year, make, model (instead of using IDLE)? Below is the cgi code I started... but fell short.
#!/usr/bin/python
import cgi
def vehicleform():
print "Content-type: text/html\n\n"
print '<html><form action="http://myhost.com/cgi-bin/car.cgi" method="get">'
print '<label>Year: <input type="text" name="year"/></label><br/><br/>'
print '<label>Make: <input type="text" name="make"/></label><br/><br/>'
print '<label>Model: <input type="text" name="model"/></label><br/><br/>'
print '<input type="submit" name="submit" value="submit"/></form></html>'
vehicleform = cgi.FieldStorage()
Any advice out there would be appreciated. Thank you.