将烧瓶应用程序部署到Apache共享主机 [英] Deploying flask app to Apache shared hosting
问题描述
我不知道这里有什么问题。
现在我被困在 .cgi
文件。
烧瓶应用程序 - hello.py:
#!/ usr / bin / python
从烧瓶导入Flask
app = Flask(__ name__)
@ app.route(/)
def hello():
返回Hello World!\\\
如果__name__ ==__main__:
app.run()
myapp.cgi文件:
#!/ usr / bin / python
import os
from wsgiref.handlers import CGIHandler
from hello import app
os.environ ['SERVER_NAME'] ='127.0.0.1'
os。 environ ['SERVER_PORT'] ='5000'
os.environ ['REQUEST_METHOD'] ='GET'
os.environ ['PATH_INFO'] =
CGIHandler ().run(app)
这两个文件都放在 / home / username / public_html / cgi-bin
目录
同样的 cgi-bin
具有名为 myenv
的目录 - 这是我创建的 virtualenv
。 virtualenv
正在启动。
现在,
我导航到cgi-bin目录并运行 -
python hello.py
我得到这个:
*在http上运行://127.0.0.1:5000 /(按CTRL + C退出)
所以这很好。现在我运行myapp.cgi文件:
python myapp.cgi
/ pre>
我得到这个:
状态:301 MOVED永久
内容类型:text / html; charset = utf-8
内容长度:251
位置:http://127.0.0.1:5000/
<!DOCTYPE HTML PUBLIC - // W3C / / DTD HTML 3.2 Final // EN>
< title>重定向...< / title>
< h1>重定向...< / h1>
< p>您应该自动重定向到目标网址:< a href =http://127.0.0.1:5000/> http://127.0.0.1:5000 /< / a> ;。如果没有点击链接。
如何将此状态设置为200 OK,
请建议。
谢谢!
解决方案我不得不在
.cgi
文件。以下是最终文件。import os
from wsgiref.handlers import CGIHandler
from hello import app
CGIHandler()。run(app)
在我的
hello.py
文件中添加了这些行:import os
import sys
sys.path.insert(0,'/home/username/public_html/cgi-bin/myenv/lib/python2.6/site-packages')
参考 - http ://www.comfycoder.com/home/how_to_deploy_a_flask_app_in_apache_shared_hosting
I am trying to deploy a simple flask application in the Apache shared hosting server.
I am not sure what is wrong here.
I am stuck at the
.cgi
file for now.The flask app - hello.py:
#!/usr/bin/python from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!\n" if __name__ == "__main__": app.run()
The myapp.cgi file:
#!/usr/bin/python import os from wsgiref.handlers import CGIHandler from hello import app os.environ['SERVER_NAME'] = '127.0.0.1' os.environ['SERVER_PORT'] = '5000' os.environ['REQUEST_METHOD'] = 'GET' os.environ['PATH_INFO'] = "" CGIHandler().run(app)
Both the files are placed in the
/home/username/public_html/cgi-bin
directoryThe same
cgi-bin
has the directory namedmyenv
- it's avirtualenv
I have created. Thevirtualenv
is active.Now,
I navigate to the cgi-bin directory and run -
python hello.py
I get this :
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
So this is fine. Now I am running the myapp.cgi file:
python myapp.cgi
I get this :
Status: 301 MOVED PERMANENTLY Content-Type: text/html; charset=utf-8 Content-Length: 251 Location: http://127.0.0.1:5000/ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <title>Redirecting...</title> <h1>Redirecting...</h1> <p>You should be redirected automatically to target URL: <a href="http://127.0.0.1:5000/">http://127.0.0.1:5000/</a>. If not click the link.
How can I make this status as 200 OK, Please suggest.
Thanks!
解决方案I had to make few changes in the
.cgi
file. Below is the final file.import os from wsgiref.handlers import CGIHandler from hello import app CGIHandler().run(app)
and added these lines in my
hello.py
file:import os import sys sys.path.insert(0, '/home/username/public_html/cgi-bin/myenv/lib/python2.6/site-packages')
Refer this - http://www.comfycoder.com/home/how_to_deploy_a_flask_app_in_apache_shared_hosting
这篇关于将烧瓶应用程序部署到Apache共享主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!