简体   繁体   English

服务器与命令行上的Python脚本

[英]Python script on server vs. command line

I have a simple hello world python script: 我有一个简单的hello world python脚本:

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

I uploaded it to my server, which has python installed, yet when I visit it in the browser by hitting http://myserver.foo/script.py , I see the script in it's entirety in the browser window. 我将它上传到我安装了python的服务器,但是当我通过点击http://myserver.foo/script.py在浏览器中访问它时,我在浏览器窗口中看到了它的全部内容。 Am I doing something wrong? 难道我做错了什么? I want to just see 'Hello World!'... 我想看看'Hello World!'......

Stupid (but mandatory) questions: 愚蠢(但强制)的问题:
1. Do you have this in either your conf file or an .htaccess (assuming Apache)? 1.你的conf文件或.htaccess (假设是Apache)中有这个吗?

AddHandler cgi-script .cgi .py

Options +ExecCGI

2. Have you chmod 'd the file to 755 ? 2.您是否chmod文件更改为755
3. Is Python at /usr/bin/python ? 3. Python在/usr/bin/python吗? (It could be C:\\Python32\\python.exe ) (可能是C:\\Python32\\python.exe


Some notes: 一些说明:

  1. I generally recommend #!/usr/bin/env python instead of #!/usr/bin/python . 我通常建议使用#!/usr/bin/env python而不是#!/usr/bin/python It is more error-proof. 它更防错。
  2. You should be using WSGI if at all possible. 尽可能使用WSGI。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM