带有子域的烧瓶中断到静态资源的链接

问题描述 投票:0回答:1

我添加了子域支持:

  1. C:\ Windows \ System32 \ drivers \ etc \ hosts:
    127.0.0.1       subdomain.test.com
  1. 烧瓶配置:
    SERVER_NAME = 'test.com:5005'
  1. 蓝图:
@app_blueprint.route('/', methods=['GET'], subdomain='<subdomain_name>') 
def index(subdomain_name):
    return redirect(url_for('app.index'))

它成功找到了路线,但是当它将模板app.html加载到浏览器中时,它无法解析静态资源:

代替

<script src="http://subdomain.test.com:5005/static/dist/app.bundle.js"></script> 

它解析为

<script src="http://test.com:5005/static/dist/app.bundle.js"></script> 

并且找不到它。

我想念什么?

更新。我根据肖恩的答案更新了主机文件。但是现在Flask找不到我重定向到的端点“ app.index”。

我指定为:

@app_blueprint.route('/app', methods=['GET'], subdomain='<subdomain_name>')
@app_blueprint.route('/app/<path:path>', methods=['GET'], subdomain='<subdomain_name>')
def index(path = None, subdomain_name=None):
    return render_template('app.html', subdomain_name=subdomain_name)

如果我直接在浏览器中使用/ app,但无法重定向,并且也找不到其他东西,则可能会击中该endpoind。

flask subdomain
1个回答
1
投票
127.0.0.1 subdomain.test.com test.com

[您告诉Flask您已安装在test.com,因此它已将/static路由安装在了那里...但是您的网络层不知道test.com在哪里,因为您没有告诉它在哪里。

© www.soinside.com 2019 - 2024. All rights reserved.