1. 程式人生 > >Flask通過藍圖設定子域名

Flask通過藍圖設定子域名

建立目錄結構

blueprints
--  __init__.py
--  cms.py
app.py

(1) app.py檔案中內容

from flask import Flask
from blueprints.cms import bp

app = Flask(__name__)

@app.route("/")
def index():
    return "index"


app.register_blueprint(bp)

class Config:
    SERVER_NAME = "test.com:5000"

app.config.from_object(Config)

if __name__ == '__main__':
    app.run()

(2) cms.py檔案

from flask import Blueprint

bp = Blueprint("cms", __name__, subdomain="cms")


@bp.route("/")
def index():
    return "show cms content"

(3) 新增hosts(我的路徑: C:\Windows\System32\drivers\etc)

127.0.0.1 test.com cms.test.com

(4) 訪問

http://test.com:5000/
http://cms.test.com:5000/