Google App Engine的app.yaml详细说明

来源:互联网 发布:linux 关闭ntpdate 编辑:程序博客网 时间:2024/05/29 03:49

http://www.ccvita.com/416.html

Google AppEngine使用一个app.yaml作为其重要的全局的配置文件。
每个独立的Google AppEngine的应用,都必须声明这样一个文件。

app.yaml使用YAML作为格式。熟悉Ruby的人应该非常熟悉yaml这种格式。

必添内容
在一个app.yaml中,必须要声明如下字段:
application
application用来唯一标示一个Google AppEngine的应用。
在开发环境中(使用dev_appserver.py),这个字段必添,但其值随意。
但是在部署环境中(应用上载至Google AppEngin的host后),
这个值必须与你申请的Google AppEngine的那个application_id一致。

application: myapp
version
version用来标示这一个Google AppEngine应用的版本。同样,在开发环境中,这个值可以随意。

runtime 和 api_version
runtime 和 api_version标示应用将依赖于那种运行环境(runtime)的哪个版本(api_version)。
当前由于只支持python,因此这两个值是固定的。

runtime: python
api_version: 1
handlers
handlers用来定义一系列url handlers,(类似于URL Mapping,如果你熟悉Spring MVC的话)。
需要为每一个handler指派一个url pattern(可以使用正则表达式)。
一旦请求的URL满足这个pattern的时候,AppEngine便会将这个请求交由这个handler所制定的对象来处理。

当需要处理动态内容时,使用script字段。script定义了用来处理这个请求的python文件路径。
handlers:
- url: /.*
script: main.py
- url: /book/.*
script: book.py
Google AppEngine在匹配url pattern的时候,使用first-match优先原则。因此上面的配置中,book.py永远也不会被使用。

当然还可以使用handler处理静态内容,如javascript脚本,或是css文件等。

-url: /static
static_dir: path/to/static
static_dir标明了静态文件所在的目录。 因此如/static/main.js的请求,Google AppEngine会到/path/to/static/main.js处寻找。

- url: /flex
static_dir: /flex

以上是初学者常会犯的错误。正确的应该是

- url: /flex
static_dir: flex

Tags: AppEngine, yaml


0 0