Forcing Python to detect DocumentRoot

Michael Torrie torriem at
Mon Jan 21 19:49:48 CET 2013

On 01/19/2013 01:01 AM, Ferrous Cranus wrote:
> # render html template and print it data = counter =
> '''<center> <a href="mailto:support at"> <img
> src="/data/images/mail.png"> </a>
> <table border=2 cellpadding=2 bgcolor=black> <td><font color=lime>
> Αριθμός Επισκεπτών </td> <td><font color=cyan> %d </td>''' % hits[0] 
> ========================================
> While from within the same file
> # open html template file f = open(
> '/home/nikos/public_html/test.txt' )
> opens OK the page file which is also past addons domain's document
> root
> Can you help to load the image? Why does it fail to load
> it? Python can have access to ANY filesystempath , no matter from
> what folder script runs from. Correct?

No I can't because doesn't "load the image."  The browser
does.  If the image fails to load it is because the apache web server
cannot find it.  In other words your image src url is bad.  It has
nothing to do with python.  Python is only spitting out html code.
That's it.  Image loading is done by apache on behalf of a request from
the web browser.  Since the url is a direct url to a file, there is no
CGI that runs.

I understand that you have a difficulty understanding the relationship
between the browser, the web server, and the cgi script.  The process
goes like this:

- browser requests the url, which happens to be the CGI script,
- web server runs returns html code to the browser.
- browser parses html code, renders it, and requests any images that the
html code references.
- Web server tries to locate the image based on its own rules and
config, and serves it if possible, otherwise, returns error 404.

So you simply have the image url wrong.  apache is not mapping /data to
where you think it is.  You have to either fix this in apache's configs,
or determine where the image really is in apache's url space, and change
the cgi to output the correct html.  Your problem isn't a python one at
all; it's an apache problem.

More information about the Python-list mailing list