Jos*_*osh 7 python hosting shared-hosting
任何人都可以协助我在Hostgator共享主机上运行Python脚本吗?我主要使用PHP,但对Python很感兴趣,并希望尝试将其发布到网上.我运行Python的唯一方法是使用解释器,或通过终端使用> Python file.py. 我尝试将hello world文件上传到Web服务器,但它输出的只是脚本源.我和hostgator谈过,但他们可以告诉我的是我需要使用一个调度员,我似乎无法找到一个例子.我想知道的是,如何向浏览器输出<p> Hello </ p>.
谢谢,对不起,如果我是漫无边际的,我一直在谷歌上搜索这一周.
好吧,我得到这个从HostGator的自己的支持网站.
假设您的主机正在运行Python 2.x,那么您可以按如下方式调整链接到脚本:
#!/usr/bin/python
print "Content-type: text/html\r\n\r\n"
print "<html><head>"
print "<title>CGI Test</title>"
print "</head><body>"
print "<p>Test page using Python</p>"
print "</body></html>"
Run Code Online (Sandbox Code Playgroud)
并将其放在您的cgi-bin
文件夹中,权限为755.
更新:在"绕过"cgi-bin文件夹方面:这将取决于您的托管包允许的选项.查看Bottle以获得适合单个Python模块的简单调度程序.您可以使用CGI部署它,
import bottle
# Put your bottle code here, following the docs on the Bottle site
bottle.run(server=bottle.CGIServer)
Run Code Online (Sandbox Code Playgroud)
进一步更新:除了Bottle文档,我建议你阅读有关CGI的Python文档.