Google App Engine(GAE)是Google提供的一個平台,讓使用者可以在這個平台上開發同時託管網路應用程式(Webapp)。免費帳戶使用GAE服務時受配額限制,程式作者可以視需要付費購買資源。GAE帳戶申請以及使用請參考Google App Engine 入門指南。
網路上除了Google提供的入門指南外,也可以找到不少參考資料:
Google 應用服務引擎開發實戰 (網路上只有範例程式,完整內容可以去圖書館借書)
Web Application Development @usfcomputerscience (英文網頁,不過講得很清楚)
另外處理中文可以參考app engine處理中文通用解法 @宅之力
底下是我(改)寫的兩個小程式給大家參考:
姓名對戰機 是我將蔡慶源的期末報告修改後移植到GAE的一個小程式。
http://ncku-mhchen-hello.appspot.com/ (Source Code)是我寫的一個小程式,功能是記錄兩個Player擲骰子的點數,架構比較簡單,有興趣的同學可以用這個架構把妳們寫的python程式移植到GAE上。
底下簡單說明一下第二個程式的內容:
因為要處理中文,所以程式開頭要加上 #coding=utf-8
程式最底下的部分
application = webapp2.WSGIApplication([ ('/', MainPage), ('/play', Playbook), ], debug=True)告訴Server網頁由哪個Handler處理:"/"由class MainPage處理;"/play"由class Playbook處理。
< form action="/play" method="post"> < p>Name of Player 1 < /p> < div> < textarea name="player_1" rows="1" cols="30"> < /textarea> < /div > < p>Name of Player 2 < /p> < div> < textarea name="player_2" rows="1" cols="30"> < /textarea> < /div > < div> < input type="submit" name="PName" value="Submit"> < /div > </form>另一種則是按鈕輸入(請看LOG_PAGE_HEADER_TEMPLATE)
< form name="input" action="/play" method="post"> < a href="/"> < button type="button">Replay< /button> < /a> < input type="submit" name="step" value="Throw Again"> </form>請注意input type裡的 name部分
player1 = self.request.get('player_1') hp_msg_u = u"{0}擲出點數{1},目前點數{2}\n" hp2 = randint(1,6) html_txt= hp_msg_u.format(player1,hp1,hp1)第二種是byte string
player2 = self.request.get('player_2') hp_msg = "{0}擲出點數{1},目前點數{2}\n" hp2 = randint(1,6) html_txt= html_txt + unicode(hp_msg.format(player2.encode('utf-8'),hp2,hp2),'utf-8')請注意第二種方式,首先在把player2填入hp_msg的format時需在欄位後加上.encode('utf-8'); 另一方面,由於html_txt在前面已經宣告是unicode string,所以要把byte string和unicode string加在一起需使用unicode轉換。