腾讯云服务器部署flask:一

app.py

from flask import Flask,jsonify
app = Flask(__name__)

app.route("/index")
def index():
    print("进入函数")
    return "hello world"


if __name__ == '__main__':
    app.run(debug=True,host="0.0.0.0")

不能访问

 原因一:防火墙未关闭

service firewalld stop  关闭防火墙

systemctl status firewall  状态为关闭状态

(flask_mini) [root@VM_0_13_centos order]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

 原因二:云服务器的安全组,为开启指定端口

flask的app访问,需要加上app(host="0.0.0.0",port=xxxxx)才可以

通过实例的公网ip加指定端口,访问获得输出字符串 hello world

# TODO

原文地址:https://www.cnblogs.com/meloncodezhang/p/12602398.html