GAE Python 3:静态文件未在本地主机上加载,但在线部署时会加载

GAE Python 3: Static files are not loading on localhost but do load when deployed online

我正在尝试将 Google App Engine Standard Flask 网络应用程序从 Python 2.7 迁移到 Python 3。它在部署到 appspot 时运行良好,但我仍然遇到运行连接本地开发服务器时出现问题。

问题是当 运行在本地开发服务器上运行时,我的应用无法找到我的静态文件。我收到此错误 Uncaught SyntaxError: Unexpected token '<',它违反了我的 jquery-3.3.1.min.js: 文件。我有理由相信正在发生的事情是它试图找到我的 JQuery 文件,失败,收到 404 错误 html 页面,并抛出语法错误,因为它期待 JavaScript 文件而不是 HTML.

我的 JQuery 文件不是唯一受影响的静态文件。例如,我的 CSS 没有加载,我的应用找不到我的本地图片。

以下是一些代码片段:

app.yaml

runtime: python38
instance_class: F4

automatic_scaling:
  max_concurrent_requests: 30

handlers:
- url: /_ah/start
  script: auto

- url: /app_shared/app_setup/app_style/*
  static_dir: app_shared/app_setup/app_style

- url: /app_shared/app_setup/app_images/*
  static_dir: app_shared/app_setup/app_images

- url: /app_shared/app_static/jquery/v_3_3_1/*
  static_dir: app_shared/app_static/jquery/v_3_3_1

- url: /app_shared/app_static/util/*
  static_dir: app_shared/app_static/util

- url: .*
  script: auto

error_handlers:
  - file: app_code/templates/errors/default.htm

  - error_code: timeout
    file: app_code/templates/errors/408_timeout.htm

h_main_header_menu.htm(在head标签内)

<script src="/app_shared/app_static/jquery/v_3_3_1/jquery-3.3.1.min.js"></script>

这是从项目根目录到 JQuery 文件的层次结构:app_shared/app_static/jquery/v_3_3_1_jquery-3.3.1.min.js

到 运行 本地开发服务器,我遵循 Google 的文档 here and here。所以我 运行 使用命令 venv\Scripts\activate 然后是 python main.py.

有人知道这里出了什么问题吗?我不知所措。在这里的任何帮助表示赞赏。提前致谢。

我明白了。我需要将 app_shared 文件夹重命名为 static。你可以在上面找到 Flask 文档 here