最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[记录]CentOS中运行Flask服务器

CentOS crifan 3261浏览 0评论

折腾:

[记录]折腾阿里云的CentOS服务器作为微信公众号的开发

期间,在:

[记录]CentOS服务器中为微信开发安装Flask服务器

之后,再去验证,搞清楚,如何让Flask运行起来。

然后接着尝试去折腾Flask:

Quickstart — Flask Documentation (0.11)

用vi hello.py

(SIPEvents)  SIPEvents cat hello.py 
from flask import Flask
app = Flask(__name__)
@app.route(‘/’)
def hello_world():
    return ‘Hello, World!’
(SIPEvents)  SIPEvents pwd
/root/SIPEvents
(SIPEvents)  SIPEvents ll
total 4.0K
-rw-r–r– 1 root root 109 Aug 15 20:53 hello.py
(SIPEvents)  SIPEvents pwd
/root/SIPEvents
(SIPEvents)  SIPEvents export FLASK_APP=hello.py
(SIPEvents)  SIPEvents flask run          
 * Serving Flask app “hello”
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

Deployment Options — Flask Documentation (0.11)

结果去访问:

http://115.29.173.126:5000/

结果出错:

然后去:

control+C去终止

再去:

(SIPEvents)  SIPEvents flask run –host=0.0.0.0
 * Serving Flask app “hello”
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
121.238.252.151 – – [15/Aug/2016 20:57:58] “GET / HTTP/1.1” 200 –
121.238.252.151 – – [15/Aug/2016 20:57:58] “GET /favicon.ico HTTP/1.1” 404 –

然后再去访问:

http://115.29.173.126:5000/

试试,就可以了:

-》

说明Flask是工作了

去加上debug参数:

(SIPEvents)  SIPEvents export FLASK_DEBUG=1
(SIPEvents)  SIPEvents flask run –host=0.0.0.0
 * Serving Flask app “hello”
 * Forcing debug mode on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: 353-795-063

然后去用浏览器去访问:

http://115.29.173.126:5000/

可以看到log输出:

121.238.252.151 – – [15/Aug/2016 20:59:48] “GET / HTTP/1.1” 200 –
121.238.252.151 – – [15/Aug/2016 20:59:55] “GET / HTTP/1.1” 200 –
121.238.252.151 – – [15/Aug/2016 20:59:55] “GET / HTTP/1.1” 200 –

就说明Flask可以基本的工作了。

转载请注明:在路上 » [记录]CentOS中运行Flask服务器

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.206 seconds, using 22.12MB memory