Python CGI
Output enviroment variables via cgi
Sample program:
#!/usr/bin/python #coding: utf-8 import cgi import os print 'Content-Type: text/html' print print ''' <html> <head> <title>Python env sample</title> </head> <body> ''' cgi.print_environ_usage() print '<hr>' print '<pre><table>' for k in os.environ.keys(): key = cgi.escape(k) env = cgi.escape(os.environ[k]) print '<tr><td>%s</td><td>%s</td></tr>' % ( key, env ) print'</table></pre>' print ''' </body> </html> '''Try sample program.
Download sample program.
Description:
#!/usr/local/bin/python #coding: utf-8Put the path of python. For some servers, it should be modified to /usr/local/bin/python or other path.
Declear that character code is utf-8.
print 'Content-Type: text/html' printIt is required to output html by CGI.
cgi.print_environ_usage()Prints a list of environment variables, used by CGI, in HTML.
os.environ.keys()Get the shell environment variables.
cgi.escape(k)Escape < -> &<,> -> &>, and so on.