问题描述
我正在尝试将Google App Engine Standard Flask Web应用程序从Python 2.7迁移到Python3。在部署到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和here。因此,我先运行venv\Scripts\activate
,然后再运行python main.py
。
有人知道这是怎么回事吗?我很茫然。感谢您的帮助。提前谢谢。
解决方法
我知道了。我需要将app_shared文件夹重命名为static。您可以在here
上找到Flask文档