python - Flask:CSS 和 JS 不会在 kubernetes POD 中加载
问题描述
当我在我的 PC 上的 Docker 中托管一个 Flask 应用程序时,CSS 和 JS 可以从模板和 HTML 视图格式正确读取。当我在 Kubernetes POD 中托管相同的应用程序时,它不会读取 CSS 和 JS。
在下面的快照中,您可以看到结果。 请在下面找到应用程序的文件结构。视图 index.html 和 upload.html 扩展了 public/templates/public_template.html,其中包含 CSS 和 JS 库的导入。
你能告诉可能是什么原因吗?kubectl 和 Docker 所需的文件结构可能不同吗?
C:.
| .gitignore
| Dockerfile
| upload_app-deploy.yaml
| run.py
|
\---app
| app.py
| requirements.txt
| __init__.py
|
+---static
| +---css
| | bootstrap.min.css
| | style.css
| |
| +---img
| | flask.png
| |
| \---js
| app.js
| bootstrap.bundle.min.js
| jquery.slim.min.js
|
\---templates
+---admin
| \---templates
\---public
| index.html
| upload.html
|
\---templates
public_template.html
浏览器中的错误:
Failed to load resource: the server responded with a status of 403 ()
jquery.slim.min.js:1 Failed to load resource: the server responded with a status of 403 ()
(index):1 Refused to apply style from 'https://ais-bt-services.asml.com/static/css/style.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
app.js:1 Failed to load resource: the server responded with a status of 403 ()
(index):1 Refused to apply style from 'https://ais-bt-services.asml.com/static/css/bootstrap.min.css' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
Dockerfile:
# Python 3 running on Debian GNU/Linux 10 (buster)(ATM) (amd64)
FROM XXX/docker/python:3
# Fill directories
COPY . /app
# Switch default directory so f.e. you don't have to provide a full pwd of req.txt
WORKDIR /app/app
# Install python packages with fixed versions
RUN pip install --force-reinstall -r requirements.txt
# Execute an app: listener and handler
CMD ["python", "/app/app/app.py"]
请在下面找到目录的权限,它们对我来说似乎没问题,目录到 775,文件到 664 和 root 用户。会不会是用户在 Kubernetes 中运行后就不同了?或者也许还有其他想法?
解决方案
推荐阅读
- heroku - Heroku Spring Redis - SessionDestroyedEvent
- python - 解析从 Internet 派生的 XML 文件
- sql - 查询重复记录
- dns - 要启用 DNSSEC,是否需要将域名服务器设置为域注册商?
- c# - 是什么导致 Xamarin Forms 构建上的“无法识别的选择器发送到类”错误?
- java - 将 Json 作为字符串接收并转换为 Java 对象
- firebase - 我们是否为 .validate() 读取收费?
- javascript - [未处理的承诺拒绝:TypeError:未定义不是函数(评估'_expo2.default.loadAsync')]
- sql - SQL 匹配一个字符串后跟一个范围内的数字
- java - Firefox 总是打开 google.com,不管 driver.get 是否指定