在主机上运行python脚本 [英] Running a python script on my hosting

查看:81
本文介绍了在主机上运行python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Web开发和Python的新手。由于我没有词汇要问确切的问题,因此这里是需要做的总结:

I am a newbie to web development and Python. Since I dont have the vocabulary to ask the exact question, here is a summary of what need to do:


  • 我有一个小型测试python cgi脚本,我已将其上传到/ home / 用户名 / pyscripts,该脚本位于 /home/username/domain.com

  • I have a small test python cgi script, which i have uploaded to /home/username/pyscripts which is above the /home/username/domain.com

我需要一个可以在URL栏中键入的链接,这将导致脚本被执行并且内容在浏览器中显示。

I need a link I can type in the URL bar, which will lead to the script being executed and the content displayed in the browser.

有人可以告诉我是否需要创建html文件,如果可以的话如何指向它python脚本域文件夹中已安装了wordpress。我的托管服务器是dreamhost共享托管服务器

Can someone tell me If i need to create an html file, and if yes how to get it to point to the python script The domain folder has wordpress installed. My hosting is dreamhost shared hosting

脚本如下:

#! /usr/bin/python

print 'Content-type: text/html'
print ''
print 'Hello, World!


推荐答案

通常,您需要将python脚本放在 / home / username / bin / 文件夹。我不确定您的特定虚拟主机是否真的允许您在/ bin文件夹之外运行Python脚本(通常不是这种情况),但如果可以,则可以替换/ pyscripts文件夹。

Usually you'd need to put your python script under the /home/username/bin/ folder. I'm not sure if your particular webhost actually allows you to run your Python script outside of the /bin folder (normally this is not the case), but if yes then you can substitute the /pyscripts folder.

URL看起来像这样: www.domain.com/bin/mypythonscript.py

The URL would look something like this: www.domain.com/bin/mypythonscript.py

或使用pyscripts文件夹(如果可能与您的虚拟主机一起使用): www.domain.com/pyscripts/mypythonscript.py

Or with the pyscripts folder (if possible with your webhost): www.domain.com/pyscripts/mypythonscript.py

您需要创建一个HTML文件,因为您在Python脚本中打印的第一行内容是告诉用户浏览器像HTML文件一样显示脚本的输出。您只需在浏览器中键入Python脚本的URL,然后服务器运行该脚本并将其输出为文本/ HTML文件,然后您的浏览器就会读取并显示该文件。

You don't need to create an HTML file as the first content line that you print in your Python script is telling the user's browser to display the output of the script like an HTML file. You simply type the URL to your python script into your browser and then the server runs the script and outputs it as a text/HTML file, which your browser then reads and displays.

此外,请不要忘记-将Python脚本文件上传到Web主机服务器上的正确文件夹后,您需要授予执行/读取/写入权限,否则它将根本无法运行。通常,这是通过您的上传实用程序(如 Filezilla )或使用诸如 chmod

Also, don't forget - you need to grant execute/read/write permission to your Python script file after you upload it to the correct folder on your webhost server or it won't run at all. Usually this is done through your upload utility like Filezilla or using a shell command like chmod.

这篇关于在主机上运行python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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