在Openshift中部署Flask [英] Deploying Flask in Openshift

查看:236
本文介绍了在Openshift中部署Flask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码在我的系统的本地主机上没有任何问题...但是在OpenShift上没有做这个工作。
我的 wsgi.py 有问题。 。我必须使用环境变量传递我的用户名和密码吗?或者我需要更改 localhost



以下是目录/存储库的树...

  myflaskaws 
├──requirements.txt
├──setup.py
├──static
│├──资产
││├──样式.css
│└──images
│├──no.png
│└──yes.png
├──模板
│├──index .html
│├──login.html
│├──searchlist.html
│├──update.html
├──test.py
├ ──test.pyc
└──wsgi.py`






wsgi.py

 #!/ usr / bin / python 
import os $ b $ virtenv = os.environ ['OPENSHIFT_PYTHON_DIR'] +'/ virtenv /'
virtualenv = os.path.join(virtenv,'bin / activate_this.py')
试试:
execfile(virtualenv,dict(__ file __ = virtualenv))
除了IOError:
通过
从测试导入a pp as application
if __name__ =='__main__':
from wsgiref.simple_server import make_server $ b $ httpd = make_server('localhost',8051,application)
print(Serving at http:// localhost:8051 / \ n按CTRL + C终止。 \\\

httpd.serve_forever()
print(Terminated !!)






test.py

 从烧瓶进口Flask 
app = Flask(__ name__)

名称 ==' main ':在 test.py


是的,你需要使用Openshift的环境变量来设置IP和端口。



 导入os 

如果os.environ中的'OPENSHIFT_APP_NAME':#我们在OPENSHIFT上?
ip = os.environ ['OPENSHIFT_PYTHON_IP']
port = int(os.environ ['OPENSHIFT_PYTHON_PORT' ])
else:
ip ='0.0.0.0'#localhost
port = 8051

httpd = make_se rver(ip,port,application)


The following codes are working without any problem in my system's localhost... But ain't doing the job on OpenShift.. There is something wrong with my wsgi.py.. Do I have to pass my username and password using environment variables OR I've need to change the localhost ?

The following is the tree of the directory/repository...

myflaskaws
├── requirements.txt
├── setup.py
├── static
│   ├── assets
│   │   ├── style.css
│   └── images
│       ├── no.png
│       └── yes.png
├── templates
│   ├── index.html
│   ├── login.html
│   ├── searchlist.html
│   ├── update.html
├── test.py
├── test.pyc
└── wsgi.py`


wsgi.py

#!/usr/bin/python
import os
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
    execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
    pass
from test import app as application
if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    httpd = make_server('localhost', 8051, application)
    print("Serving at http://localhost:8051/ \n PRESS CTRL+C to Terminate. \n")
    httpd.serve_forever()
    print("Terminated!!")


test.py

from flask import Flask
app = Flask(__name__)

PS : I'm not using "if name == 'main':" in test.py

解决方案

Yes, you do need to use Openshift's environment variables to set up the IP and port.

Try adding in the below code to setup the proper IP and port depending if you are on OS or localhost.

Import os

if 'OPENSHIFT_APP_NAME' in os.environ:              #are we on OPENSHIFT?
    ip = os.environ['OPENSHIFT_PYTHON_IP']
    port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
else:
    ip = '0.0.0.0'                            #localhost
    port = 8051

httpd = make_server(ip, port, application)

这篇关于在Openshift中部署Flask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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