盖伊附录yaml对于静态页面和Python

2024-04-26 00:28:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试为一个Google应用程序创建一个静态html组件(可以脱机使用),而这个应用程序不是Python。你知道吗

我似乎无法为此正确配置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)

Tags: app应用程序urlyamlindexpnghtmlrequired
1条回答
网友
1楼 · 发布于 2024-04-26 00:28:27

您的\/(static)\/(index)\.html模式是无效的URL regex模式。你知道吗

首先-模式不能以\开头-您不需要转义/。你知道吗

模式中的圆括号用于标识位置分组,这些位置分组可以在随后的语句中被\1\2等称为参数,例如static_files。从Handlers elements表的url行:

url

Required element under handlers. The URL pattern, as a regular expression. The expression can contain groupings that can be referred to in the file path to the script with regular expression back-references. For example, /profile/(.)/(.) would match the URL /profile/edit/manager and use edit and manager as the first and second groupings.

如果您不需要这样的分组/参数,那么就不要在模式中使用圆括号。所以要匹配/static/index.html,您可以:

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

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

- url: /static
  static_dir: static

相关问题 更多 >