Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Cloud9上运行Python CGI_Python_Cgi_Cloud9 Ide - Fatal编程技术网

在Cloud9上运行Python CGI

在Cloud9上运行Python CGI,python,cgi,cloud9-ide,Python,Cgi,Cloud9 Ide,我可以让Python CGI程序在其他环境中运行,但有助于使用Cloud9环境访问“hello world” 我的简单程序运行得很好,但我甚至无法获得一个简单程序的HTML/web版本 这次跑步给了我一个建议: 您的代码正在运行。 重要提示:在脚本中使用os.getenv(端口,8080)作为端口,使用os.getenv(IP,0.0.0.0)作为主机 但我不知道该怎么办 下面是我的简单代码。我还尝试将其作为filename.cgi运行,但这不起作用 #!/usr/bin/env python

我可以让Python CGI程序在其他环境中运行,但有助于使用Cloud9环境访问“hello world”

我的简单程序运行得很好,但我甚至无法获得一个简单程序的HTML/web版本

这次跑步给了我一个建议: 您的代码正在运行。
重要提示:在脚本中使用os.getenv(端口,8080)作为端口,使用os.getenv(IP,0.0.0.0)作为主机

但我不知道该怎么办

下面是我的简单代码。我还尝试将其作为filename.cgi运行,但这不起作用

#!/usr/bin/env python
print "Content-Type: text/html"
print "<html>"
print "<head><title>My first CGI program</title></head>"
print "<body>"
print "<p> It works!! </p>"
print "</body></html>"
#/usr/bin/env python
打印“内容类型:文本/html”
打印“”
打印“我的第一个CGI程序”
打印“”
打印“它可以工作!!

” 打印“”
您需要先安装Flask,您可以通过以下命令进行安装:

$ sudo easy_install Flask
您的代码应该是smth,如下所示:

import os
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    html=  "<html>"
    html+= "<head><title>My first CGI program</title></head>"
    html+= "<body>"
    html+= "<p> It works!! </p>"
    html+= "</body></html>"
    return html

app.run(host = os.getenv('IP','0.0.0.0'), port=int(os.getenv('PORT',8080)))

现在您可以打开了,它将工作

您正在运行内置的runner吗?上述行是否打印到控制台上?关于如何运行代码(或设置apache以提供cgi)的更多细节将有助于找到解决方案。我试图从终端运行Apache并加载CGI库,但没有成功。对于Python CGI,我是否应该在Cloud9上使用特殊的runner构建?那会让世界变得更简单!!谢谢请发送电子邮件至support@c9.io使用您的用户名和工作区名称,我将尝试查看
Your code is running at https://workspacename-username.c9users.io.
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)