Google App Engine 初學, 此篇主要是介紹 app.yaml 設定, 並且寫個簡單的範例測試.
app.yaml 設定檔
- vim app.yaml # 設定檔範例如下
application: hello # 應用程式名稱, 需與 Google Apps 上面設定的名字一致
version: 1 # version, GAE 會幫你做版本控管, 由此可以隨時切換各種版本
runtime: python # 執行的程式語言
api_version: 1 # 使用 1.x.x 的最新版
default_expiration: "7d 1h" # 過期時間 for static filehandlers:
- url: /
script: main.py
- url: /test
script: test.py
- url: /req
script: req.py
- url: /favicon.ico
static_files: favicon.ico
upload: favicon.ico
mime_type: image/x-icon
- url: /logo.jpg
static_files: logo.jpg
upload: logo.jpg
- url: /static
static_dir: static
CGI 範例
- vim /var/gae/req.py
# -*- coding: utf-8 -*-
import cgiform = cgi.FieldStorage()
q = form.getvalue('q', 'default-value')print 'Content-Type: text/html; charset=utf-8'
print """
<html>
<head></head>
<body><p> Hello, %s </p>
<form method="post">
<input type="text" name="q" value="">
<input type="submit" value="post">
<form>
</body>
</html>
""" % q - /var/gae/dev_appserver.py hello # 開啟 Local 測試
- http://localhost:8080/req
- http://localhost:8080/req?q=test
- http://localhost:8080/req # 於頁面送 post 看看