在本地服务器上运行python脚本只显示源代码

时间:2016-05-03 09:25:20

标签: python

我对Python运行问题有疑问。 我使用python -m http.server 8000命令使用Windows命令提示符设置本地服务器,但是当我在http://localhost:8000/cgi-bin/hello.py上运行脚本时,它只显示源代码而不是实际运行脚本。

我使用this链接上的代码。

#!/usr/bin/python

print('Content-Type: text/html')
print()
print('<html>')
print('<head><title>Hello from Python</title></head>')
print('<body>')
print('<h2>Hello from Python</h2>')
print('</body></html>')

我看到有几个人遇到同样的问题,但我无法找到解决方案。 我使用Python 3.5

1 个答案:

答案 0 :(得分:1)

您应该关注the documentation。 Python 3的命令是:

python -m http.server --cgi 8000
相关问题