[Tutor] returning a web page (and also path to web root)

Barnaby Scott barnabydscott at yahoo.com
Mon Dec 15 17:07:21 EST 2003


Thanks very much. In fact I like the look of your
first idea the best - the Location: thing. Even
shorter and more concise than I had hoped for!

I think both my problems in fact stem from more lack
of knowledge of http and webservers than Python, so
forgive me if this is all slightly off-topic.

The problem I feared does in fact occur - I used
urllib to get a page and display it, and sure enough
the images sources and some links failed to work.
Because they are relative references, they went from
the wrong starting point - i.e. not the web directory
of the page, but cgi-bin where the script lives.

As for the web root thing: I can get the DOCUMENT_ROOT
to display, but this appears to be a totally different
directory to the one I am interested in! My situation
is that I have rented space on a server for 3 domains.
The path I want returned takes the following form:

/home/myaccountname/webs/www.oneofmydomains.com/htdocs

The DOCUMENT_ROOT returns instead:

/usr/local/www/data

When I look there, the stuff is nothing to do with me
at all! 


--- Lloyd Kvam <pythontutor at venix.com> wrote:
> (I already suggested using the Location: HTTP
> header, but decided to
> add more.)
> Barnaby Scott wrote:
> > I am trying to write a cgi script in which under
> rare
> > circumstances I want the user to see a particular
> web
> > page (from the same server).
> > 
> > I am not very experienced and would be very
> grateful
> > for help on the right way to tackle this - without
> > knowing a sensible direction to go in I am likely
> to
> > waste huge amounts of time developing a stupid or
> > overly-complex solution!
> > 
> > Presumably if I just read the page in and spat it
> back
> > out to the user, all the relative links, image
> sources
> > etc would be wrong.
> Not true.  Your script will operate relative to the
> cgi-bin directory.
> However, if you simply copy a page of HTML back to
> the browser, the
> browser will not know that your CGI sent the HTML as
> opposed to the
> regular HTTPD server.  It will simply process the
> HTML it receives.
> Your script would have trouble resolving the image
> tags and relative
> links, but it does not have to resolve anything
> within the HTML.
> > 
> > However I was a little reluctant to start messing
> with
> > the SimpleHTTPServer module - a. because I find it
> > daunting and b. I wondered if there was something
> > altogether simple and obvious I could do.
> > 
> > One more quick question: is there an easy way of
> > returning the actual path of the webserver's web
> root?
> > (Forgive my terminology if it's not right - I mean
> the
> > root directory as far as the someone accessing the
> > site is concerned).
> Shell Environment:
> 
> DOCUMENT_ROOT
>      /var/www/html
> 
> The os.environment() method should give you the
> DOCUMENT_ROOT.
> The test method of the cgi module will show the
> environment provided
> by your web server along with any parameters.
> To see it yourself, this is all you need:
> 
> #!/usr/local/bin/python
> import cgi
> cgi.test()
> 
> Fix the shebang for your situation.
> > 
> > __________________________________
> > Do you Yahoo!?
> > New Yahoo! Photos - easier uploading and sharing.
> > http://photos.yahoo.com/
> > 
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> > 
> 
> -- 
> Lloyd Kvam
> Venix Corp.
> 1 Court Street, Suite 378
> Lebanon, NH 03766-1358
> 
> voice:	603-653-8139
> fax:	801-459-9582
> 


__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/



More information about the Tutor mailing list