Python Pages


Web Programming


Chapter 7

More notes on debugging

To watch the the Apache error log have:

tail -f /usr/local/apache/logs/error.log

To make sure the HTML form is sending the corrrect information, run:

printquery.py or printparams.py

Or, start your script with:

import cgi, sys
cgi.test()
sys.exit()

Or, start your script with:

print 'Content-type: text/plain'
print
sys.stderr = sys.stdout

Once the script is running, use cgi module functions:

print_environ() prints the shell environment variables in HTML

print_form(form) printe the contents of the form in HTML
where form is the FieldStorage you read from the input

print_directory() prints the current directory in HTML
checking you are at the eight directory and the right files are present

Use hidden fields:

input type="hidden" name=string value=string

When the CGI program sends a cookie to the browser,
it will include in the MIME header:

Sending a cookie back to the client:

print 'Set-cookie: name=value; options'

path=directories - cookie sent when returning to host
and the path begins with directories

domain=domainName - cookie sent to hosts on the domain
domain=.python.stardevsoft.com - sent to x.python.stardevsoft.com
but not php.stardevsoft.com

expire=weekday, dd-mm-yy hh:mm:ss GMT
expire=Tuesday, 30-Aug-2005 09:00:00 GMT

to create time:
import time

rightnow=time.time()
later=time.gmtime(rightnow+168*60*60)
date=time.strftime('%A, %d-%b-%Y %H:%M:%S GMT', later)

When the browser sends the cookie back to the server,
it will include in the MIME header:

Cookie: name=value ; name=value ; ...
Note that value may not have spaces, tabs, or semicolons
urllib contains functions to encode and decode URL-encoded strings.


[Web Programming] [Python Pages]

[Main]