我有一个Flask应用程序,它使用Flask引导(V3.3.7.1),使用引导文件的本地服务
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/代理传递时工作正常
您需要添加引导样式表
https://diyprojects.io/flask-bootstrap-html-interface-effortless-python-projects/#.YEi-_HVKi4A
您可以使用目录跳到:
添加引导样式表
引导\u服务\u本地,因为您尚未将其导出到静态目录
相关问题 更多 >
编程相关推荐