Quick and easy - showing Python data hander output via a browser
Archive - Originally posted on "The Horse's Mouth" - 2013-05-15 20:17:13 - Graham EllisFrom today's intermediate Python course - a new example of how to very quickly present the results of running an application on the web - [here].
The objective was to provide an almost-trivial way of letting results be viewed via a remote browser. No forms, no validation needed, no formatting of the plain text output. I used the oldfashioned common gateway interface.
My script starts:
#!/usr/bin/env python
print "Content-type: text/html\n"
And that's to tell the Apache httpd web server that the script is written in Python, and that the output is HTML.
You also need to enable CGI in your httpd.conf file (or a file it includes) and set the file to be executable.
In order to have the code that normally prints the results to file / stdout in a fixed width font, you'll want to put it within a preformatted style, or <pre> tag pair.
print "<pre>"
Output code goes here
print "</pre>"