【问题标题】:GAE - app.yaml for static page AND PythonGAE - 静态页面和 Python 的 app.yaml
【发布时间】:2018-05-22 12:39:53
【问题描述】:

我正在尝试为原本是 Python 的 Google 应用创建一个静态 html 组件(可以离线使用)。

我似乎无法为此正确配置 app.yaml 文件。

handlers:

  # Serve images and JSON as static resources.
- url: /(.+\.(gif|png|jpg|json|ico))$
  static_files: \1
  upload: .+\.(gif|png|jpg|json|ico)$
  application_readable: true

- url: \/(static)\/(index)\.html
  static_files: static/\1/index.html
  upload: static\/index.html

- url: /
  script: roomusage.app
  login: required
  secure: always

- url: /welcome
  script: roomusage.app
  login: required
  secure: always

- url: /record
  script: record_usage.app
  login: required
  secure: always

这是我收到的错误消息:

appcfg.py: error: Error parsing C:\gcloud\dev-myapp\app.yaml: Unable to assign value '\/(static)\/(index)\.html' to attribute 'url':
Value '\/(static)\/(index)\.html' for url does not match expression '^(?:(?!\^)/.*|\..*|(\(.).*(?!\$).)$'
  in "C:\gcloud\dev-myapp\app.yaml", line 25, column 8.
2017-12-08 09:27:50 (Process exited with code 2)

【问题讨论】:

  • \/(static)\/(index)\.html 模式可能是可疑的。您尝试与哪些 URL 匹配,您想在其中识别哪些参数?
  • 我正在尝试匹配的网址:/static/index.html(不明白问题的第二部分)

标签: python google-app-engine static app.yaml


【解决方案1】:

您的 \/(static)\/(index)\.html 模式是无效的 URL 正则表达式模式。

首先 - 模式不能以 \ 开头 - 你不需要转义 /

模式中的圆括号用于标识位置分组,然后可以在后续语句中将其称为\1\2 等的参数,例如static_files。来自Handlers elements 表中的url 行:

网址

处理程序下的必需元素。 URL 模式,作为常规 表达。表达式可以包含可以引用的分组 使用正则表达式在脚本的文件路径中 反向引用。例如,/profile/(.)/(.) 将匹配 URL /profile/edit/manager 并使用 editma​​nager 作为 第一组和第二组。

如果您不需要此类分组/参数,请不要在您的模式中使用圆括号。所以要匹配 /static/index.html 你可以:

- url: /static/index\.html
  static_files: static/index.html
  upload: static/index.html

但您应该注意,如果您还拥有上述内容,则上述内容是多余的:

- url: /static
  static_dir: static

【讨论】:

    猜你喜欢
    • 2013-03-28
    • 2011-11-10
    • 2011-07-11
    • 2012-09-03
    • 1970-01-01
    • 2012-11-13
    • 2016-11-16
    • 1970-01-01
    • 2013-04-01
    相关资源
    最近更新 更多