BASIC CGI PROGRAMMING

The basic process of setting up your Python based CGI application is to start by sending back the HTTP header. The Python cgi module does not provide any solutions for generating this information for you. This means that you will need to translate any CGI module instructions of the form:

use CGI;

my $query = new CGI;
print $query->header('text/html');

into a Python print statement:

print 'Content-type: text/html\r\n\r\n',

To get the information supplied to fields in a form, the easiest method is to use the param() function in the Perl CGI module:

use CGI;

my $name = param('name');
my @options = param('options');

In Python this translates to using the getvalue() function:

 import cgi name = cgi.getvalue('name') options ...

Get Perl To Python Migration now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.