コンテンツへスキップ

(オフィシャルサイトの日本語訳)スタートガイド:webapp2フレームワークの説明

2012/12/31

https://developers.google.com/appengine/docs/python/gettingstartedpython27/usingwebapp

Explaining the webapp2 Framework

webapp2フレームワークの説明

The WSGI standard is simple, but it would be cumbersome to write all of the code that uses it by hand. Web application frameworks handle these details for you, so you can focus your development efforts on your application’s features. Google App Engine supports any framework written in pure Python that speaks WSGI, including DjangoCherryPyPylons,web.py, and web2py. You can bundle a framework of your choosing with your application code by copying its code into your application directory.

WSGI標準は単純ですが、それを使用するすべてのコードを手で書くのは面倒でしょう。 Webアプリケーションフレームワークは、あなたのためにこれらの詳細を処理しますので、あなたのアプリケーションの機能に開発労力を集中することができます。 Google App Engineは、Django、CherryPy、Pylons、web.pyと、web2pyを含むWSGIに対応した純粋なPythonで書かれた任意のフレームワークをサポートしています。あなたのアプリケーションディレクトリに自身のコードをコピーして、アプリケーション·コードを使用して、選択したフレームワークをバンドルすることができます。

App Engine includes a simple web application framework, called webapp2. The webapp2 framework is already installed in the App Engine environment and in the SDK, so you do not need to bundle it with your application code to use it. We will use webapp2 for the rest of this tutorial.

App Engineはwebapp2と呼ばれるシンプルなWebアプリケーションフレームワークが含まれています。 webapp2フレームワークは、すでにApp Engine環境とSDKのインストールされているので、あなたはそれを使用するためにアプリケーションのコードと同梱する必要はありません。我々は、このチュートリアルの後半では、webapp2を使用します。

Hello, webapp2!

webapp2 application has two parts:

webapp2アプリケーションは2つの部分があります。

  • one or more RequestHandler classes that process requests and build responses
  • WSGIApplication instance that routes incoming requests to handlers based on the URL

1つもしくはそれ以上のRequestHandlerクラスは、そのプロセスの要求と応答を構築します。
WSGIApplicationインスタンスは、ハンドラへの着信要求をURLに基​​づいてルーティングします。

Let’s take another look at our friendly greeting application:

私達の簡単な挨拶アプリケーションをもう一度見てみましょう。

import webapp2

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

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

What webapp2 Does

webapp2は何をするか

This code defines one request handler, MainPage, mapped to the root URL (/). When webapp2 receives an HTTP GET request to the URL /, it instantiates the MainPage class and calls the instance’s get method. Inside the method, information about the request is available using self.request. Typically, the method sets properties on self.response to prepare the response, then exits. webapp2 sends a response based on the final state of the MainPage instance.

このコードは、ルートURL(/)にマッピングされたリクエストハンドラ、MainPageを定義しています。 webapp2がHTTP URLにGETリクエストを受信すると/は、MainPageクラスをインスタンス化し、インスタンスのgetメソッドを呼び出します。メソッド内で、要求に関する情報がself.requestを使用することで利用可能となります。通常、このメソッドは、終了した後、応答を準備するself.responseのプロパティを設定します。 webapp2はMainPageのインスタンスの最後の状態に基づいて応答を送信します。

The application itself is represented by a webapp2.WSGIApplication instance. The parameter debug=true passed to its constructor tells webapp2 to print stack traces to the browser output if a handler encounters an error or raises an uncaught exception. You may wish to remove this option from the final version of your application.

アプリケーション自体はwebapp2.WSGIApplicationインスタンスによって表されます。 パラメータ debug= trueは、コンストラクタは、ハンドラがエラーを検出したか、キャッチされない例外が発生した場合、ブラウザの出力にスタックトレースを印刷しwebapp2に指示します。あなたのアプリケーションの最終バージョンにおいては、このオプションを削除するケースが多いでしょう。

We’ll use a few more features of webapp2 later in this tutorial. For more information about webapp2, see the webapp2 documentation.

我々は、このチュートリアルの後半でwebapp2のいくつかの機能を使用することにします。 webapp2の詳細については、webapp2マニュアルを参照してください。

コメントする

コメントを残す