騰訊雲服務器部署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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM