python apache cgi 图片显示_如何在Python CGI页面中加载/显示图片

I have written a little survey using Python and CGI. I am trying to show a picture using the normal tag, But even-though the picture is in the same directory as my cgi script, my script cannot show it. I also changed the header to this:

print "Content-type: text/html; image/jpeg"

print

print """

You are going to be redirected

Helloooo

cat

"""

Why?(it is a very small jpg file)

解决方案print "Content-type: text/html; image/jpeg"

Don't change the header to that. You can't have multiple content types for a single document (multipart documents excluded, but browsers don't support them and that isn't the right format).

You are delivering an HTML document with an reference to an image in it. The image will be a separate request and response.

print "Content-type: text/html"

Or, better:

print "Content-type: text/html; charset=utf-8"

(Assuming you are using utf-8, which you should be).

print """

Your Doctype is missing. This will trigger quirks mode, which is undesirable. You also have a great deal of legacy presentational markup that should be replaced by CSS.

cat

The context suggests that the image is decorative, so the alternative text should probably be "" (see Alt texts in IMGS), but there is nothing wrong with the actual reference to the image.

But even-though the picture is in the same directory as my cgi script

Since the HTML seems to be OK. You need to check that the image is.

Can you reach the image by typing the URL in directly?

What do the web server logs say when you try?

It is possible that your server is configured to try to treat everything in the directory as an executable, no matter what the file extension, so it might be trying to run the image as if it were a CGI program (which will obviously fail). If so, then you could either move the image or change the configuration of the server.

And I've just noticed this comment:

I did this in my browser: localhost/cgi-bin/cat.jpg and it got an error, I checked the logs, it Exec format error: exec of '/home/hossein/public_html/cgi-bin/cat.jpg' failed

That is what is happening. Moving the image is the simplest solution.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值