简体   繁体   English

GAE-适用于静态页面和Python的app.yaml

[英]GAE - app.yaml for static page AND Python

I am trying to create a static html component (that will be usable offline) for a Google App that is otherwise Python. 我正在尝试为否则为Python的Google App创建一个静态html组件(可离线使用)。

I can't seem to get the app.yaml file configured correctly for that. 我似乎无法为此正确配置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

Here's the error message I'm getting: 这是我收到的错误消息:

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)

Your \\/(static)\\/(index)\\.html pattern is an invalid URL regex pattern. 您的\\/(static)\\/(index)\\.html模式是无效的URL正则表达式模式。

First - the pattern can't start with \\ - you don't need to escape / . 首先-模式不能以\\开头-您不需要转义/

The round paranthesis in the pattern are used to identify positional groupings which can then be referred to as parameters by \\1 , \\2 , etc in subsequent statements, like static_files , for example. 模式中的圆括号用于识别位置分组,然后在后续语句(例如static_files其称为\\1\\2等参数。 From the url row in the Handlers elements table: 处理程序元素表中的url行:

url 网址

Required element under handlers . 处理程序下的必需元素。 The URL pattern, as a regular expression. URL模式,作为正则表达式。 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. 例如, / profile /(。 )/(。将匹配URL / profile / edit / manager,并使用editmanager作为第一和第二分组。

If you don't need such grouping/parameters then don't use the round paranthesis in your patterns. 如果不需要这样的分组/参数,则不要在模式中使用圆括号。 So to match just /static/index.html you could have: 因此,仅匹配/static/index.html您可以:

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

But you should note that the above is redundant if you also have: 但是您应该注意,如果您还具有以下内容,则以上内容是多余的:

- url: /static
  static_dir: static

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM