有关python服务器端脚本的更多帮助 [英] a little more help with python server-side scripting

查看:58
本文介绍了有关python服务器端脚本的更多帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我联系了我的域名主机,了解了如何在他们的

服务器上实现Python,并得到了这样的回复:


-------- -----------

你好John,


请注意我们服务器中python的实现是

通过mod_python与apache集成。


这些是您能够直接运行.py脚本所需的步骤

来自浏览器你的网页:


1.请使用下面提到的python路径:

#!/ usr / bin / env python

此外,使用脚本路径更新我们,以便我们可以在服务器上设置

脚本的相应所有权和权限。


如果您需要任何进一步的帮助,请随时与我们联系。

-----------------------


不幸的是,我不太明白我需要做什么

现在。我在哪里提到他们提到的路径?我的

脚本路径是什么意思?

I contacted my domain host about how Python is implemented on their
server, and got this response:

-------------------
Hello John,

Please be informed that the implementation of python in our server is
through mod_python integration with the apache.

These are the steps needed for you to be able to run .py script directly
from browser for your webpage:

1. Please use the below mentioned path for python:
#!/usr/bin/env python

Furthermore, update us with the script path, so that we can set the
appropriate ownership and permissions of the script on the server.

If you require any further assistance, feel free to contact us.
-----------------------

Unfortunately, I don''t completely understand what it is I need to do
now. Where do I put the path they mentioned? And what do they mean by my
script path?

推荐答案

John Salerno写道:
John Salerno wrote:
我联系了我的域名主机,了解了如何在他们的服务器上实现Python,并得到了这样的回复:

------------------ -
你好约翰,

请注意,我们服务器中的python实现是通过mod_python与apache集成的。

这些是您可以从浏览器直接为您的网页运行.py脚本所需的步骤:

1.请使用下面提到的python路径:
#!/ usr / bin / env python

此外,使用脚本路径更新我们,以便我们可以在服务器上设置相应的脚本所有权和权限。
如果您需要任何进一步的帮助,请随时与我们联系。
-----------------------

不幸的是,我不完全明白它是什么现在就去做。我在哪里提到他们提到的路径?我的
脚本路径是什么意思?



Python教程应填写空白

http://www.python.org/doc/tut/node4.html): 2.2.2可执行的Python脚本
#! / usr / bin / env python

(假设解释器在用户的PATH上)在脚本的开头,给文件一个可执行模式。 #!必须是文件的前两个字符。在某些平台上,第一行必须以Unix风格的行结尾(\ n)结束,而不是Mac OS(\ r)或
Windows(" \\ n \\ n)行结束。请注意,散列或磅字符
#用于在Python中启动注释。


这回答了你的第一个问题。放在 #!位于

..py脚本的顶部。这样Web服务器就会知道如何运行脚本。

使用
chmod命令可以为脚本提供可执行模式或权限:

I contacted my domain host about how Python is implemented on their
server, and got this response:

-------------------
Hello John,

Please be informed that the implementation of python in our server is
through mod_python integration with the apache.

These are the steps needed for you to be able to run .py script directly
from browser for your webpage:

1. Please use the below mentioned path for python:
#!/usr/bin/env python

Furthermore, update us with the script path, so that we can set the
appropriate ownership and permissions of the script on the server.

If you require any further assistance, feel free to contact us.
-----------------------

Unfortunately, I don''t completely understand what it is I need to do
now. Where do I put the path they mentioned? And what do they mean by my
script path?

The Python tutorial should fill in the blanks
(http://www.python.org/doc/tut/node4.html): 2.2.2 Executable Python Scripts

On BSD''ish Unix systems, Python scripts can be made directly executable,
like shell scripts, by putting the line

#! /usr/bin/env python

(assuming that the interpreter is on the user''s PATH) at the beginning
of the script and giving the file an executable mode. The "#!" must be
the first two characters of the file. On some platforms, this first line
must end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or
Windows ("\r\n") line ending. Note that the hash, or pound, character,
"#", is used to start a comment in Python.
This answers your first question. Put the #! bit at the top of your
..py script. This way the web server will know how to run the script.
The script can be given a executable mode, or permission, using the
chmod command:


chmod + x myscript.py
chmod +x myscript.py




这就回答了你的问题。您的主机需要知道您的

脚本的路径,以便他们可以使用chmod使其可执行。


--Ben


John Salerno写道:
John Salerno wrote:
我联系了我的域名主机,了解了如何在他们的服务器上实现Python,并得到了这样的响应:

-------------------
你好John,

请注意我们服务器中python的实现是通过mod_python与apache集成的。

这些是您能够直接从浏览器为您的网页运行.py脚本所需的步骤:

1.请使用下面提到的python路径:
#!/ usr / bin / env python

此外,用脚本路径更新我们,以便我们可以设置
服务器上脚本的适当所有权和权限。

如果您需要任何进一步的帮助,请随时与我们联系。
--------- --------------

Unf幸运的是,我现在还不完全明白我需要做什么。我在哪里提到他们提到的路径?我的
脚本路径是什么意思?
I contacted my domain host about how Python is implemented on their
server, and got this response:

-------------------
Hello John,

Please be informed that the implementation of python in our server is
through mod_python integration with the apache.

These are the steps needed for you to be able to run .py script directly
from browser for your webpage:

1. Please use the below mentioned path for python:
#!/usr/bin/env python

Furthermore, update us with the script path, so that we can set the
appropriate ownership and permissions of the script on the server.

If you require any further assistance, feel free to contact us.
-----------------------

Unfortunately, I don''t completely understand what it is I need to do
now. Where do I put the path they mentioned? And what do they mean by my
script path?




别担心,看起来好像他们也不完全理解: - )


幸运的是,他们已经为您提供了运行CGI

脚本所需的信息。尝试在cgi-bin目录中安装此脚本test.py

(您可能必须将其设置为可执行文件):


#!/ usr / bin / env python



import os

print" Content-Type:text / plain"

print

for os in os.environ.items():

print"%s =%s" %t


如果您访问 http://yourdomain/cgi-bin/test.py 它看起来好像你很高兴你会好起来的!


问候

史蒂夫

-

Steve Holden +44 150 684 7255 +1 800 494 3119

Holden Web LLC < a rel =nofollowhref =http://www.holdenweb.comtarget =_ blank> www.holdenweb.com

PyCon TX 2006 www.python.org/pycon/



Don''t worry, it looks as though they don''t completely understand either :-)

Fortunately they''ve given you the information you need to run CGI
scripts. Try installing this script in your cgi-bin directory as test.py
(you may have to set it executable):

#!/usr/bin/env python
#
import os
print "Content-Type: text/plain"
print
for t in os.environ.items():
print "%s=%s" % t

If it runs when you access http://yourdomain/cgi-bin/test.py it looks
like you''re good to go!

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/


这篇关于有关python服务器端脚本的更多帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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