dackdive's blog

新米webエンジニアによる技術ブログ。JavaScript(React), Salesforce, Python など

Google App Engine Python Tutorialのメモ(1)

突然ですがGoogle App Engineの勉強をし始めました。
言語はpython 2.7です。
公式チュートリアルを一通りやるので、とりあえず自分用のメモを残しておきます。

Chapter1, 2は触りの部分なので、 Chapter 3 Explaining webapp2 Frameworkから。

(追記)その後のメモ

Chapter 3 Explaining webapp2 Framework

  • webapp2というのはGAEが用意したフレームワーク(Djangoとかと同じ位置づけ)

  • webapp2.WSGIApplicationのところでURLと使用するクラスを対応づけてる。
    ので、たとえば

import webapp2

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, World!')

application = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)

というサンプルコードを

import webapp2

class MainPage(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Hello, World!')

class MainPage2(webapp2.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('hogehoge')

application = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/get', MainPage2),
], debug=True)

って変更して、http://localhost:8080/get にアクセスすると
"Hello, World!"のかわりに"hogehoge"が表示される。

  • webapp2についてもう少し詳しく勉強するにはこのあたりを参考に。

https://developers.google.com/appengine/docs/python/tools/webapp2?hl=ja

http://webapp-improved.appspot.com/

Chapter 4 Using the Users Service

新しくでてきたメソッドなど

# Checks for active Google account session
user = users.get_current_user()
self.redirect(users.create_login_url(self.request.uri))
  • Userについてもっと知りたい場合はこちら

https://developers.google.com/appengine/docs/python/users/?hl=ja