3

I am beginner and i dont know where i am doing mistake. i have seen these stack posts Return an image to the browser in python, cgi-bin , Return Image from python CGI using javascript and How to loading/show a picture in a Python CGI page but got no help.

Here is the code:

#!C:\Python27\python

text = """Content-type: text/html\n

<TITLE> CGI 101 </TITLE>
<H1>A SECOND CGI SCRIPT </H1>
<HR>
<P> HELLO,CGI WORLD!</P>
<img src="../imag000.jpg" width=101 height=64 border=0 alt="">
<HR>
"""

print (text)

and on browser it appears small box which is not showing image, like this:

enter image description here

Kindly help.

and folder which contains image is cgi. Kindly see picture:

enter image description here

11
  • 1
    The mime type of your data isn't image/png but text/html. If you change that, provided you have the image at the location you specify, it should show up. Commented Nov 30, 2015 at 10:34
  • but picture is not coming Commented Nov 30, 2015 at 10:41
  • here is my update: #!C:\Python27\python text = """Content-type: text/html\n <TITLE> CGI 101 </TITLE> <H1>A SECOND CGI SCRIPT </H1> <HR> <P> HELLO,CGI WORLD!</P> <img src="../imag001.jpg" width=101 height=64 border=0 alt=""> <HR> """ print (text) Commented Nov 30, 2015 at 10:42
  • see pic for understanding tinypic.com/r/10p4toh/9 Commented Nov 30, 2015 at 10:45
  • I am. Try structuring your html as it should be structured. With the proper header, doctype, etc. Commented Nov 30, 2015 at 10:49

2 Answers 2

2

Here is the best Solution:

<img src="http://localhost/imag000.jpg" width=101 height=64 border=0 alt="">
Sign up to request clarification or add additional context in comments.

1 Comment

yh thanx for appreciating my own effort :)
0

The HTML claims that the image is in the parent directory, but the server has it in the same directory. Either modify the HTML to match the current image location, or move the image to where the browser is requesting it from.

7 Comments

i am sorry i did nt understand where is browser if requesting from? phpmyadmin folder?
ummm i am doing on python-cgi by placing "Content-type: text/html\n"
That's nice. Read the HTML.
u mean i shd create html pages?
i think u saying i dont know html? whereas my question is how shall i use <img src="imag000.jpg" > in cgi bcz text is coming nicely.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.