繁体   English   中英

在Cloud9上运行Python CGI

[英]Running Python CGI on Cloud9

我可以使Python CGI程序在其他环境中运行,但是很有价值,可以帮助Cloud9环境进入“ hello world”。

我的简单程序运行良好,但是我什至无法获得简单程序的HTML / Web版本。

运行给我建议:您的代码在https://workspacename-username.c9.io上运行。
重要:在脚本中,使用os.getenv(PORT,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>"

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

$ sudo easy_install Flask

您的代码应该像这样:

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)))

开始申请后,您将看到

Your code is running at https://workspacename-username.c9users.io.
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)

现在您可以打开https://workspacename-username.c9users.io ,它将起作用

暂无
暂无

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

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