python not executed and code is shown literal in t

2019-02-27 16:05发布

问题:

In ubuntu 12.04 i have this basic http server:

python -m SimpleHTTPServer

And this file demo.py

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

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

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?

回答1:

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.