App Engine: How to configure app.yaml for a flask app? Error: index.html not found
App Engine: How to configure app.yaml for a flask app? Error: index.html not found
我使用 Python 3.7 构建了一个 Flask 应用程序。该设置在本地工作。上传到 GAE 时,出现内部服务器错误。 GAE 仪表板显示 index.html
未找到。此问题与 app.yaml
文件有关吗?
我的项目结构如下:
root/
|-app.yaml
|-requirements.txt
|-main.py
|-other model files that feed into main.py
|-templates/
|-index.html
|-index2.html
|-js
|-css
|-images
app.yaml
runtime: python37
# [START handlers]
handlers:
- url: /.*
script: auto
- url: /index.html
static_files: templates/index.html
upload: Templates/index.html
- url: /templates
static_dir: Templates
- url: /(.*\.(css|js|png|jpg))
static_files: templates/
upload: templates/(.*)
# [END handlers]
App Engine handlers
element 文档指出:
Patterns are evaluated in the order they appear in the app.yaml
file, from top to bottom. The first mapping whose pattern matches the URL is the one used to handle the request.
- 将 catch-all 处理程序放在最后。
- 不需要将
templates
目录添加到 URL 处理程序。
- 按照惯例,
templates
目录应该是小写的。此外,如果 URL 处理程序确实需要引用 templates
,app.yaml
模式区分大小写(如 Dan Cornilescu 所述),使用小写有助于避免不匹配。
- 标准设置是在
templates
目录旁边创建一个单独的 static
(and/or assets
)目录。 static
目录将包含 Javascript、CSS 和图像等文件。
项目结构
root/
|-app.yaml
|-requirements.txt
|-main.py
|-other model files that feed into main.py
|-static/
|-js
|-css
|-images
|-templates/
|-index.html
|-index2.html
app.yaml
runtime: python37
handlers:
- url: /static
static_dir: static
- url: /.*
script: auto
我使用 Python 3.7 构建了一个 Flask 应用程序。该设置在本地工作。上传到 GAE 时,出现内部服务器错误。 GAE 仪表板显示 index.html
未找到。此问题与 app.yaml
文件有关吗?
我的项目结构如下:
root/
|-app.yaml
|-requirements.txt
|-main.py
|-other model files that feed into main.py
|-templates/
|-index.html
|-index2.html
|-js
|-css
|-images
app.yaml
runtime: python37
# [START handlers]
handlers:
- url: /.*
script: auto
- url: /index.html
static_files: templates/index.html
upload: Templates/index.html
- url: /templates
static_dir: Templates
- url: /(.*\.(css|js|png|jpg))
static_files: templates/
upload: templates/(.*)
# [END handlers]
App Engine handlers
element 文档指出:
Patterns are evaluated in the order they appear in the
app.yaml
file, from top to bottom. The first mapping whose pattern matches the URL is the one used to handle the request.
- 将 catch-all 处理程序放在最后。
- 不需要将
templates
目录添加到 URL 处理程序。 - 按照惯例,
templates
目录应该是小写的。此外,如果 URL 处理程序确实需要引用templates
,app.yaml
模式区分大小写(如 Dan Cornilescu 所述),使用小写有助于避免不匹配。 - 标准设置是在
templates
目录旁边创建一个单独的static
(and/orassets
)目录。static
目录将包含 Javascript、CSS 和图像等文件。
项目结构
root/
|-app.yaml
|-requirements.txt
|-main.py
|-other model files that feed into main.py
|-static/
|-js
|-css
|-images
|-templates/
|-index.html
|-index2.html
app.yaml
runtime: python37
handlers:
- url: /static
static_dir: static
- url: /.*
script: auto