CGI: Run Script then load page

Tom Bryan tbryan at python.net
Sat Aug 4 22:09:03 EDT 2001


Lang wrote:

> How do I call the script, run the commit,
> and then return to a given URL as one step instead of two?

I don't remember how/when I figured this out.  I either saw it in a 
script used by Mark Peskin for PERCEPS, or I looked it up in the 
HTTP RFC.  

------ simple_redirect.py ------
#!/usr/bin/env python
"""A simple CGI script that sends users elsewhere"""
print "Location: http://www.python.org/\n\n"

------

I'm not really a Web programmer, so it may be that some browsers 
don't respect the Location header.  In that case, you might want to 
use something more like this in an actual application unless you 
know that the simple_redirect.py works for all browsers.

------ redirect.py ------
#!/usr/bin/env python
"""A fairly simple CGI script that sends users elsewhere""" 

print "Content-Type: text/html"  # Just in case the redirect doesn't work.
print "Location: http://www.python.org/\n\n"  # redirect
# Just in case the redirect doesn't work.
print """<html>
<head>
    <meta http-equiv="refresh" content="0;url=http://www.python.org/">
    <title>Redirect</title>
</head>
<body>
    Return to <a href="http://www.python.org/">Python web site</a>
</body>
</html>
"""
------

sending-users-elsewhere-for-2-years-ly yours
---Tom




More information about the Python-list mailing list