Forcing Python to detect DocumentRoot
torriem at gmail.com
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 = f.read() counter =
> '''<center> <a href="mailto:support at superhost.gr"> <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
> While from within the same counter.py 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
> Can you help counter.py to load the image? Why does it fail to load
> it? Python can have access to ANY filesystempath , no matter from
> what folder counter.py script runs from. Correct?
No I can't because counter.py 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, counter.py.
- web server runs counter.py 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