Python, cgi and redirect
David Rock
rockdw at bigfoot.com
Fri May 19 20:41:39 EDT 2000
I think it's worth it to mention one more detail about this:
You can write a redirect directly into the header of the HTML (before the
<HTML> tag)
print 'Content-type: text/html'
print 'Refresh: 1; URL=/whatever.html'
print
print
print <HTML> ....
-Rock
Teemu Keskinarkaus wrote:
> On Wed, 10 May 2000 10:20:37 GMT, nascheme at enme.ucalgary.ca (Neil
> Schemenauer) wrote:
>
> >Teemu Keskinarkaus <teemu.keskinarkaus at ramk.fi> wrote:
> >>Is there simple cgi module for python that can do redirect?? Now I'm
> >>doing redirect in cgi-script like this:
> >>
> >>print "Status: 302 Moved"
> >>print "Location: http://url.to.somewhere"
> >>
> >>That works fine except I get 'Premature end of script headers' errors
> >>in apache error_log everytime I use that script.
> >
> >You need to terminate the headers with a empty line ("\r\n"):
> >
> > sys.stdout.write("Status: 302 Moved\r\n"
> > "Location: http://url.to.somewhere\r\n"
> > "\r\n")
> >
> >I think most clients will accept "\n" although it is not
> >technically correct.
> Thanks for everyone who answered. I got it working right. I put empy
> 'print' at the end to do extra line and now there is no more errors in
> log when I'm using script!
>
> TK
More information about the Python-list
mailing list