0

Actually i want to insert an image in a web application which uses Python as server side scripting language. I am using Python 2.7 version in windows platform. I have written a simple script to insert an image in python language.

print "<img src='image.png'>"

Even in this script i am not getting any errors or warnings and the page is getting executed successfully but the image is not getting displayed. Also the specified image file exists in the same folder where the python file exists and even if we provide an absolute path of the image in src attribute of img tag Shall i import any extra packages? if yes, then please mention them. Please anybody suggest a solution to this problem.

4
  • 1
    Which of the web server are you using? Apache? And instead of accessing that page, does image show up when you access http://.../image.png ? Commented May 3, 2011 at 13:52
  • i'm using xampp server which has apache server and mysql dbms package... Commented May 3, 2011 at 16:12
  • @m3rLinEz-while accessing the image directly as you have mentioned http://.../image.png i got this error [an error occurred while processing this directive] The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script. [an error occurred while processing this directive] Commented May 4, 2011 at 4:31
  • Well then it looks like the web server is not currently serving the image file correctly .. Commented May 4, 2011 at 11:13

2 Answers 2

1

No, you need not import any extra packages. Just use raw string in Python because if your path contains \n like characters, it should be interpreted for newline. Like this

print r'<img src="c:\path\new\image.png'

But when are printing html in server-side, you are actually doing CGI programming and I would suggest to start with some good tutorials.

Sign up to request clarification or add additional context in comments.

Comments

1

This isn't a python issue, this is an issue with the HTML you are outputting.

The tag is fine. Have you checked that the extension of the image is the same, and that the case (capitalization) is exactly the same? If the file is named imAge.PNG and you put image.png it won't work.

Also, check the path you used. Make sure you are using forward slashes (/).

1 Comment

as u have mentioned i have checked the file the extension is in the lower case also other types of images such as .jpg also not working.

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.