[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Python CGI & Webpage with an Image

rodmc

3/5/2008 2:47:00 PM

Hi,

I have a set of CGI scripts set up and in one page (which is stored in
an HTML file then printed via a python CGI) there is an image. However
the image never displays, can anyone recommend a way round this
problem?

Kind regards,

rod
6 Answers

Miki

3/5/2008 3:51:00 PM

0

Hello Rod,

> I have a set of CGI scripts set up and in one page (which is stored in
> an HTML file then printed via a python CGI) there is an image. However
> the image never displays, can anyone recommend a way round this
> problem?
We need more information, can you post a code snippet? error page? ...

My *guess* is that the web server don't know how to server the image
(wrong path configuration?)

HTH,
--
Miki <miki.tebeka@gmail.com>
http://pythonwise.bl...

rodmc

3/6/2008 9:37:00 AM

0

Hi,

Good point, some code samples is probably required. Please note that
for reasons of integration with another system I am not using a
templating system.


Anyway I have copied them below:

Python:

f = open("finish.html")
doc = f.read()
f.close()
print doc


HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html;
charset=windows-1252">
<TITLE></TITLE>
</HEAD>
<BODY LANG="en-GB" DIR="LTR">
<P><IMG SRC="banner.jpg" NAME="graphics1" ALIGN=LEFT WIDTH=799
HEIGHT=137 BORDER=0><BR CLEAR=LEFT><BR><BR>
</P>
<P>Thank you for uploading your file</P>
</BODY>
</HTML>

Bryan Olson

3/6/2008 10:46:00 AM

0

rodmc wrote:
[...]
> Python:
>
> f = open("finish.html")
> doc = f.read()
> f.close()
> print doc

You might need to start with:

print "Content-Type: text/html"
print

Is "finish.html" in the right place? When you browse to your
script, can you see that you're getting the html?

> HTML:
[...]
> <P><IMG SRC="banner.jpg" NAME="graphics1" ALIGN=LEFT WIDTH=799

I suspect a server configuration and/or resource placement problem.
The image has a relative URL, and the user's browser will look for
it on the same path that it used to get the resource served by the
cgi script, up to last '/'.

Is banner.jpg in the right place, and is your web server configured
to treat everything in that directory as a cgi script, and thus
trying to execute the jpg? If one of those is the problem, just
move banner.jpg, and/or change the relative URL. For example,
SRC="../banner.jpg" will cause the browser to look for the jpg
one directory above.

Failing that, can look at the web server's log?

--
--Bryan

rodmc

3/6/2008 11:43:00 AM

0

Hi,

Thanks for your very quick response. I have played around a bit more
so that both the image and HTML file are in the public_html folder.
They are called via python using a relative URL, and have permissions
set to 755. Within the HTML file the image is accessed using just
"banner.jpg". The actual page displays ok except for the image - so it
has the same problem as before. However when the same page is
displayed without running through a CGI it displays perfectly.

Kind regards,

rod

On Mar 6, 11:46 am, Bryan Olson <fakeaddr...@nowhere.org> wrote:
> rodmc wrote:
>
> [...]
> > Python:
> >
> > f = open("finish.html")
> > doc = f.read()
> > f.close()
> > print doc
>
> You might need to start with:
>
> print "Content-Type: text/html"
> print
>
> Is "finish.html" in the right place? When you browse to your
> script, can you see that you're getting the html?
>
> > HTML:
> [...]
> > <P><IMG SRC="banner.jpg" NAME="graphics1" ALIGN=LEFT WIDTH=799
>
> I suspect a server configuration and/or resource placement problem.
> The image has a relative URL, and the user's browser will look for
> it on the same path that it used to get the resource served by the
> cgi script, up to last '/'.
>
> Is banner.jpg in the right place, and is your web server configured
> to treat everything in that directory as a cgi script, and thus
> trying to execute the jpg? If one of those is the problem, just
> move banner.jpg, and/or change the relative URL. For example,
> SRC="../banner.jpg" will cause the browser to look for the jpg
> one directory above.
>
> Failing that, can look at the web server's log?
>
> --
> --Bryan



Bryan Olson

3/6/2008 8:05:00 PM

0

rodmc wrote:
> [...] I have played around a bit more
> so that both the image and HTML file are in the public_html folder.
> They are called via python using a relative URL, and have permissions
> set to 755. Within the HTML file the image is accessed using just
> "banner.jpg". The actual page displays ok except for the image - so it
> has the same problem as before. However when the same page is
> displayed without running through a CGI it displays perfectly.

Is the cgi script in the same directory? The user's browser looks
for the jpg relative to the URL it used to get the page, which in
the case of the CGI script is the path to the script, not the
path to the html file.

If server logs are hard to get or read, try my runcgi.py script:

http://aspn.activestate.com/ASPN/Cookbook/Python/Rec...


--
--Bryan

rodmc

3/8/2008 7:41:00 PM

0


> Is the cgi script in the same directory? The user's browser looks
> for the jpg relative to the URL it used to get the page, which in
> the case of the CGI script is the path to the script, not the
> path to the html file.


No the CGI script is in a different folder, I could move everything to
the same folder I guess.


> If server logs are hard to get or read, try my runcgi.py script:
>
> http://aspn.activestate.com/ASPN/Cookbook/Python/Rec...

Thanks, I will try this.

Rod