我有一个使用 Flask Bootstrap (V3.3.7.1) 的 Flask 应用程序,使用引导文件的本地服务。
bootstrap = Bootstrap(app)
app.config['BOOTSTRAP_SERVE_LOCAL'] = True
我将此应用程序嵌入到 iFrame 中,该 iFrame 通过代理传递这些请求,一旦我离开应用程序的根路径,加载这些静态文件时就会出现 404 错误。
我的项目结构非常简单——
$ tree
.
+-- app
¦ +-- api.py
¦ +-- forms.py
¦ +-- __init__.py
¦ +-- routes.py
¦ +-- templates
¦ +-- base.html
¦ +-- index.html
¦ +-- login.html
¦ +-- logs.html
¦ +-- scaninvestigation.html
+-- config.py
+-- pilotscriptsui.py
+-- requirements.txt
+-- run.sh
模板本身内部没有任何自定义内容覆盖这些路径 - 一切都使用默认值。
> cat app/templates/scaninvestigation.html
{% extends "base.html" %}
{% import 'bootstrap/wtf.html' as wtf %}
{% block app_content %}
...
{% endblock %}
以下是这些静态文件的工作请求的日志 -
192.168.64.8 - - [12/Feb/2021 12:55:17] "GET https://flask-dev-app.internal-apps.com:9999/ HTTP/1.1" 200 -
2021-02-12 12:55:17 - _internal._log (113) - INFO - 192.168.64.8 - - [12/Feb/2021 12:55:17] "GET https://flask-dev-app.internal-apps.com:9999/ HTTP/1.1" 200 -
2021-02-12 12:55:18 - routes.before_request (100) - INFO - Remote User: 43316732
192.168.64.8 - - [12/Feb/2021 12:55:18] "GET https://flask-dev-app.internal-apps.com:9999/static/bootstrap/css/bootstrap.min.css?bootstrap=3.3.7.1.dev1 HTTP/1.1" 200 -
2021-02-12 12:55:18 - _internal._log (113) - INFO - 192.168.64.8 - - [12/Feb/2021 12:55:18] "GET https://flask-dev-app.internal-apps.com:9999/static/bootstrap/css/bootstrap.min.css?bootstrap=3.3.7.1.dev1 HTTP/1.1" 200 -
2021-02-12 12:55:18 - routes.before_request (100) - INFO - Remote User: 43316732
192.168.64.8 - - [12/Feb/2021 12:55:18] "GET https://flask-dev-app.internal-apps.com:9999/static/bootstrap/jquery.min.js?bootstrap=3.3.7.1.dev1 HTTP/1.1" 200 -
2021-02-12 12:55:18 - _internal._log (113) - INFO - 192.168.64.8 - - [12/Feb/2021 12:55:18] "GET https://flask-dev-app.internal-apps.com:9999/static/bootstrap/jquery.min.js?bootstrap=3.3.7.1.dev1 HTTP/1.1" 200 -
2021-02-12 12:55:18 - routes.before_request (100) - INFO - Remote User: 43316732
192.168.64.8 - - [12/Feb/2021 12:55:18] "GET https://flask-dev-app.internal-apps.com:9999/static/bootstrap/js/bootstrap.min.js?bootstrap=3.3.7.1.dev1 HTTP/1.1" 200 -
2021-02-12 12:55:18 - _internal._log (113) - INFO - 192.168.64.8 - - [12/Feb/2021 12:55:18] "GET https://flask-dev-app.internal-apps.com:9999/static/bootstrap/js/bootstrap.min.js?bootstrap=3.3.7.1.dev1 HTTP/1.1" 200 -
这是我们离开根路径后的日志,我开始为所有资源获取 404,并且 CSS 或 JS 在远程页面上都不起作用。/scaninvestigation
您可以看到它正在新路径而不是上面工作的根路径中寻找静态资源。
2021-02-12 12:56:32 - routes.before_request (100) - INFO - Remote User: 43316732
192.168.64.8 - - [12/Feb/2021 12:56:32] "GET https://flask-dev-app.internal-apps.com:9999/scaninvestigation HTTP/1.1" 200 -
2021-02-12 12:56:32 - _internal._log (113) - INFO - 192.168.64.8 - - [12/Feb/2021 12:56:32] "GET https://flask-dev-app.internal-apps.com:9999/scaninvestigation HTTP/1.1" 200 -
2021-02-12 12:56:32 - routes.before_request (100) - INFO - Remote User: 43316732
192.168.64.8 - - [12/Feb/2021 12:56:32] "GET https://flask-dev-app.internal-apps.com:9999/scaninvestigation/static/bootstrap/css/bootstrap.min.css?bootstrap=3.3.7.1.dev1 HTTP/1.1" 404 -
2021-02-12 12:56:32 - _internal._log (113) - INFO - 192.168.64.8 - - [12/Feb/2021 12:56:32] "GET https://flask-dev-app.internal-apps.com:9999/scaninvestigation/static/bootstrap/css/bootstrap.min.css?bootstrap=3.3.7.1.dev1 HTTP/1.1" 404 -
2021-02-12 12:56:33 - routes.before_request (100) - INFO - Remote User: 43316732
192.168.64.8 - - [12/Feb/2021 12:56:33] "GET https://flask-dev-app.internal-apps.com:9999/scaninvestigation/static/bootstrap/jquery.min.js?bootstrap=3.3.7.1.dev1 HTTP/1.1" 404 -
2021-02-12 12:56:33 - _internal._log (113) - INFO - 192.168.64.8 - - [12/Feb/2021 12:56:33] "GET https://flask-dev-app.internal-apps.com:9999/scaninvestigation/static/bootstrap/jquery.min.js?bootstrap=3.3.7.1.dev1 HTTP/1.1" 404 -
2021-02-12 12:56:33 - routes.before_request (100) - INFO - Remote User: 43316732
192.168.64.8 - - [12/Feb/2021 12:56:33] "GET https://flask-dev-app.internal-apps.com:9999/scaninvestigation/static/bootstrap/js/bootstrap.min.js?bootstrap=3.3.7.1.dev1 HTTP/1.1" 404 -
2021-02-12 12:56:33 - _internal._log (113) - INFO - 192.168.64.8 - - [12/Feb/2021 12:56:33] "GET https://flask-dev-app.internal-apps.com:9999/scaninvestigation/static/bootstrap/js/bootstrap.min.js?bootstrap=3.3.7.1.dev1 HTTP/1.1" 404 -
关于我可以做些什么来解决这个问题以及它为什么会发生的任何想法?这些 CSS 文件是 Python 库的默认文件,并且在不通过 iFrame / 代理传递时可以正常工作。