带子域的Flask断开到静态资源的链接

带子域的Flask断开到静态资源的链接,flask,subdomain,Flask,Subdomain,我添加了子域支持: C:\Windows\System32\drivers\etc\hosts: 烧瓶配置: 蓝图: @app_blueprint.route('/',方法=['GET'],子域='') def索引(子域名称): 返回重定向(url_用于('app.index')) 它成功找到路由,但将模板app.html加载到浏览器时,无法解析静态资源: 而不是 <script src="http://subdomain.test.com:5005/static/dist/app.bu

我添加了子域支持:

  • C:\Windows\System32\drivers\etc\hosts:
  • 烧瓶配置:
  • 蓝图:
  • @app_blueprint.route('/',方法=['GET'],子域='')
    def索引(子域名称):
    返回重定向(url_用于('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\u blueprint.route('/app',methods=['GET'],subdomain='')
    @app_blueprint.route('/app/',方法=['GET'],子域='')
    def索引(路径=无,子域名称=无):
    返回呈现模板('app.html',subdomain\u name=subdomain\u name)
    

    如果我直接在浏览器中使用/app,则可以点击此端点,但重定向不起作用,并且也找不到其他内容。

    您还需要将
    test.com
    添加到您的
    /etc/hosts
    别名:

    127.0.0.1       subdomain.test.com  test.com
    

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

    谢谢,它成功了!但现在我有另一个问题——出于某种原因,它找不到它(404)。我错了,以前它引发了一些其他异常。我现在也出现了以下异常“服务器端错误:无法为端点“app.index”生成url。您是否忘记指定值['path'、'subdomain_name']?”我更新了我的问题。谢谢好的,没关系,修复了在执行重定向时提供子域名作为参数的问题。
    <script src="http://test.com:5005/static/dist/app.bundle.js"></script> 
    
    @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)
    
    127.0.0.1       subdomain.test.com  test.com