python未执行,代码在页面中显示为文字 [英] python not executed and code is shown literal in the page

查看:76
本文介绍了python未执行,代码在页面中显示为文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 ubuntu 12.04 中,我有这个基本的 http 服务器:

In ubuntu 12.04 i have this basic http server:

python -m SimpleHTTPServer

还有这个文件 demo.py

And this file demo.py

#!/usr/bin/python2.7
print "Content-Type: text/html"
print
print """\
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
"""

但是当我打开时:http://127.0.0.1:8000/demo.py

However when I open: http: //127.0.0.1:8000/demo.py

我在浏览器中收到一个带有 demo.py 文字的页面.显然,我们所期望的是 hello world.

i receive a page with the demo.py literal in the browser. Obviously what is expected is hello world.

有什么问题?有什么想法吗?

What is the problem? any idea?

推荐答案

SimpleHTTPServer 只能提供静态页面,不能提供 CGI 脚本.您可以改用 CGIHTTPServer.

SimpleHTTPServer can only serve static pages, not CGI scripts. You could use CGIHTTPServer instead.

用于本地测试设置;这些服务器几乎没有在更广泛的网络上经过实战测试,几乎可以肯定是不安全的.

Use this only for local testing setups; these servers have hardly been battletested on the wider web and are almost certainly not secure.

这篇关于python未执行,代码在页面中显示为文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆