Page 1 of 1

Embarassingly Dumb HTML Question

Posted: 2008.10.07 (01:19)
by t̷s͢uk̕a͡t͜ư
I have an image. It's in /var/www/img/, and it's called fox_dog.png.
I have an Apache2 server running out of /var/www.
The following HTML code loads it perfectly:

Code: Select all

<img src="img/fox_dog.png">
Can anyone -- anyone at all -- tell me why the above code, when generated through a Python CGI script using Apache2's mod_python module, consistently fails to load that same picture?
The only difference is that it's being generated by the script, which shouldn't actually even matter because the script doesn't process the HTML in the slightest, and merely returns it as a string to the Apache2 server, which should then process it in exactly the same way as the quick test HTML file.

Things to note:
Everyone and their grandmothers have write permissions to /var/www and /var/www/img. I've been easily able to create, destroy, and manipulate content in these directories without a hitch.
While it has been discovered that the prime working directory that the CGI script uses is just root ( '/', without the 'var/www' part), just in case that matters in the slightest for some reason once the HTML is generated and processed by Apache2, the following variations have also failed:

Code: Select all

<img src="/var/www/img/fox_dog.png">
<img src="var/www/img/fox_dog.png">
Even when changing the current working directory within the CGI script to /var/www, the following variations have failed:

Code: Select all

<img src="img/fox_dog.png">
<img src="./img/fox_dog.png">
<img src="/var/www/img/fox_dog.png">
This is driving me insane, and it's so, so ridiculously simple an issue...

Re: Embarassingly Dumb HTML Question

Posted: 2008.10.07 (01:27)
by xeronix
might it be the directory that the picture is in doesnt correspond with the coding?

Re: Embarassingly Dumb HTML Question

Posted: 2008.10.07 (02:45)
by Atilla
I'm assuming you've used this for other images and it works? (i.e. it's not that the quotation marks or other odd characters in the output are somehow screwing up your Python.)

Re: Embarassingly Dumb HTML Question

Posted: 2008.10.07 (04:15)
by smartalco
I believe you need "/img/fox_dog.png"

without the first slash the path is relative, with it, the path is from the web root in Apache

Re: Embarassingly Dumb HTML Question

Posted: 2008.10.08 (08:52)
by scythe
Add an alt="STRING" to it, to see if Python is passing the code correctly.
i.e. <img src="img/fox_dog.png" alt="I go chop your dollar">

Re: Embarassingly Dumb HTML Question

Posted: 2008.10.08 (16:07)
by AlliedEnvy
Just to make sure we're on the same page, you've checked the source of the page generated by your code, and the source contains exactly

Code: Select all

<img src="img/fox_dog.png">
?

Re: Embarassingly Dumb HTML Question

Posted: 2008.10.08 (17:31)
by t̷s͢uk̕a͡t͜ư
Just for the record, I'm not leaving this thread hanging or anything - the server running all this is at my place of employ and some moron decided it'd be a good idea to turn it off. I'll have more to say when I'm at work again.
xeronix wrote:might it be the directory that the picture is in doesnt correspond with the coding?
No, it's there alright. I can open that image (via copy-pasting the src string) in an image viewer, and as I said, everyone and their grandmother has read and write permissions to it.
Besides which, the test page I wrote works absolutely fine:

Code: Select all

<html><head/><body><img src="img/fox_dog.png"></body></html>
That loads the image perfectly.
scythe wrote:Add an alt="STRING" to it, to see if Python is passing the code correctly.
i.e. <img src="img/fox_dog.png" alt="I go chop your dollar">
Already did. The alt text loads instead of the image every time.
smartalco wrote:I believe you need "/img/fox_dog.png"

without the first slash the path is relative, with it, the path is from the web root in Apache
I can't believe I didn't think of this.
Thanks. I'll try it.
Atilla wrote:I'm assuming you've used this for other images and it works? (i.e. it's not that the quotation marks or other odd characters in the output are somehow screwing up your Python.)
The Python script is returning syntactically correct HTML, but in fact, no images I try to load will work if it's the Python script that's generating the HTML.
AE wrote:Just to make sure we're on the same page, you've checked the source of the page generated by your code, and the source contains exactly

Code: Select all

<img src="img/fox_dog.png">
?
Yes. Exactly that.

The generated source is something like:

Code: Select all

<html><head><title>my title</title></head><body>
Blah blah: <input ...><br>
Blah blah blah: <input ...><br>
Blah:<br><textarea ...><br><br>
Image:<br>
<img src="img/fox_dog.png">
</body></html>
It really is just that simple. I'm not doing anything fancy whatsoever.

Re: Embarassingly Dumb HTML Question

Posted: 2008.10.08 (18:13)
by AlliedEnvy
Well, I dunno. You say it's generating syntactically correct HTML. Have you run it through a verifier? Also, it might be a good idea to look at the error console and other dev tools that come with your browser. It's hard for me to believe that the problem is due how your source is being generated, and a lot more likely (to me) that the generated source itself has an error in some way.

Re: Embarassingly Dumb HTML Question

Posted: 2008.10.08 (19:49)
by t̷s͢uk̕a͡t͜ư
AlliedEnvy wrote:Well, I dunno. You say it's generating syntactically correct HTML. Have you run it through a verifier? Also, it might be a good idea to look at the error console and other dev tools that come with your browser. It's hard for me to believe that the problem is due how your source is being generated, and a lot more likely (to me) that the generated source itself has an error in some way.
I can tell that it's syntactically correct because I can view the generated source through my browser as though it was any other HTML file. I mean, the page loads just fine - it just can't find the image.
...the problem was that I wasn't giving the path correctly:
smartalco wrote:I believe you need "/img/fox_dog.png"

without the first slash the path is relative, with it, the path is from the web root in Apache
That did the trick. I can't believe that escaped me.
Thanks.

Re: Embarassingly Dumb HTML Question

Posted: 2008.10.10 (02:31)
by smartalco
I am the master at answering embarrassingly easy HTML questions (or you can take out either one of those conditions, I can answer embarrassingly easy general questions or very specific HTML questions as well)