【发布时间】:2021-05-16 06:17:06
【问题描述】:
我有一个使用 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 / Proxy 传递时可以正常工作。
【问题讨论】:
-
您能否通过查看源代码 (CTRL + U) 看到呈现的 html 内容,并检查引导 src 位置。由于相对 URL 而不是 Flask boostrap 问题,这似乎是前端问题。
标签: python flask twitter-bootstrap-3 flask-bootstrap