response

□未翻訳

翻訳中

□翻訳完了(細田謙二)

■レビュー(中垣健志)

response

responseは、もう1つのStorageインスタンスです。以下のものを格納しています:

response is another instance of the Storage class. It contains the following:

response.body: StringIOオブジェクトです。web2pyはこれに対して出力ページの本体を書き込みます。!!この変数は決して変更しないでください!!

a StringIO object into which web2py writes the output page body. NEVER CHANGE THIS VARIABLE.

response.cookies: request.cookiesと似ていますが、後者はクライアントからサーバーに送られるクッキーを格納するのに対し、前者はサーバーからクライアントに送られるクッキーを格納します。セッションクッキーは自動的に処理されます。

similar to request.cookies, but while the latter contains the cookies sent from the client to the server, the former contains cookies sent by the server to the client. The session cookie is handled automatically.

response.download(request, db): アップロードされたファイルのダウンロードを可能にするコントローラ関数を実装する際に用いるメソッドです。

a method used to implement the controller function that allows downloading of uploaded files.

response.files: ページで必要なJSとCSSの一覧です。これらは、標準の"layout.html"のヘッダーにて、自動的にリンクが追加されます。新しいCSSやJSファイルを含めるには、このリストに追加するだけです。重複処理は行われます。順序は意味を持ちます。

a list of CSS and JS required by the page. They will automatically be linked in the header of the standard "layout.html". To include a new CSS or JS file, just append it to this list. It will handle duplicates. The order is significant.

response.flash: ビューに組み込まれるオプションパラメータです。通常は何か起こったことをユーザに通知するために使用されます。

optional parameter that may be included in the views. Normally used to notify the user about something that happened.

response.headers: HTTPレスポンスヘッダのためのdictです。

a dict for HTTP response headers.

response.menu: ビューに組み込まれるオプションパラメータです。通常はビューにナビゲーションメニューツリーを渡すために使用されます。MENUヘルパーでレンダリングすることができます。

optional parameter that may be included in the views, normally used to pass a navigation menu tree to the view. It can be rendered by the MENU helper.

response.meta: response.meta.author、かつ/または、response.meta.description 、response.meta.keywordsのような、省略可能なメタ情報を格納する(辞書的な)ストレージオブジェクトです。メタ変数の内容は、自動的に正しいMETAタグに入れられます。これは、 デフォルトでは、"views/layout.html"によって組み込まれる"web2py_ajax.html"内のコードによって行われます。

a storage object (like a dict) that contains optional meta storage information like response.meta.author, response.meta.description, and/or response.meta.keywords. The content of the meta variable is automatically placed in the proper META tag by the code in "web2py_ajax.html" with is included by default by "views/layout.html".

response.postprocessing: これは関数のリストです。デフォルトは空です。この中の関数はアクションの出力時に、ビューによって出力がレンダリングされる前に、レスポンスオブジェクトをフィルタするために用いられます。これは、他のテンプレート言語のサポートを実装するために利用できます。

this is a list of functions, empty by default. These functions are used to filter the response object at the output of an action, before the output is rendered by the view. It can be used to implement support for other template languages.

response.render(view, vars): コントローラ内部のビューを明示的に呼び出すためにに使用するメソッドです。viewはオプションパラメータで、ビューファイルの名前を指定します。varsは、ビューに渡される名前付けされた値の辞書です。

a method used to call the view explicitly inside the controller. view is an optional parameter which is the name of the view file, vars is a dictionary of named values passed to the view.

response.session_file: セッションを格納するファイルストリームです。

file stream containing the session.

response.session_file_name: セッションが保存されるファイルの名前です。

name of the file where the session will be saved.

response.session_id: 現在のセッションIDです。IDは自動的に決定されます。この変数は決して変更しないでください。

the id of the current session. It is determined automatically. NEVER CHANGE THIS VARIABLE.

response.session_id_name: このアプリケーションのセッションクッキーの名前です。この変数は決して変更しないでください。

the name of the session cookie for this application. NEVER CHANGE THIS VARIABLE.

response.status: レスポンスに渡されるHTTPステータスコードの数字です。デフォルトは200(OK)です。

the HTTP status code integer to be passed to the response. Default is 200 (OK).

response.stream(file, chunk_size, request=request): コントローラがこれを返す時、web2pyはファイルの内容をchunk_sizeのブロックごとにクライアントに戻します。requestパラメータは、HTTPヘッダにおいてチャンクの開始を行うのに必要です。

when a controller returns it, web2py streams the file content back to the client in blocks of size chunk_size. The requestparameter is required to use the chunk start in the HTTP header.

response.subtitle: ビューに組み込まれるオプションパラメータです。ページのサブタイトルを格納します。

optional parameter that may be included in the views. It should contain the subtitle of the page.

response.title: ビューに組み込まれるオプションパラメータです。ページのタイトルを格納し、ヘッダのHTMLタイトルTAGによってレンダリングされます。

optional parameter that may be included in the views. It should contain the title of the page and should be rendered by the HTML title TAG in the header.

response._vars: この変数は、アクションではなく、ビューにおいてのみアクセス可能です。アクションがビューに対して返す値を格納します。

this variable is accessible only in a view, not in the action. It contains the value returned by the action to the view.

response.view: ビューのテンプレートの名前です。このテンプレートはページを必ずレンダリングします。デフォルトでは次のように設定されています:

the name of the view template that must render the page. This is set by default to:

1.

"%s/%s.%s" % (request.controller, request.function, request.extension)

上記のファイルがない場合は、次のようになります。

or, if the above file cannot be located, to

1.

"generic.%s" % (request.extension)

この変数の値を変えると、特定のアクションに関連付けられたビューファイルが変更されます。

Change the value of this variable to modify the view file associated with a particular action.

response.xmlrpc(request, methods): コントローラがこれを返す時、この関数はXML-RPCを介して公開されます。この関数は、第9章で説明するより良い方法が存在するため、現在は推奨されていません。

when a controller returns it, this function exposes the methods via XML-RPC46 . This function is deprecated since a better mechanism is available and described in Chapter 9.

response.write(text): 出力ページのボディにテキストを書くメソッドです。

a method to write text into the output page body.

response.js は、Javascriptのコードを格納することができます。レスポンスが第13章で説明するweb2pyコンポーネントによって受け取られた場合に限り、このコードが実行されます。

can contain Javascript Code. This code will be executed if and only if the response is received by a web2py component as discussed in Chapter 13.

responseはgluon.storage.Storageオブジェクトです。ビューに渡す他の属性も格納することができます。技術的な制約はありませんが、全体的なレイアウト("layout.html")にあるすべてのページによってレンダリングさ れる変数だけを保存することを推奨します。

Since response is a gluon.storage.Storage object it can be used to store other attributes that you may want to pass to the view. While there is no technical restriction our recommendation is to store only variables that are to be rendered by all pages in the overall layout ("layout.html").

いずれにせよ、ここに記載した変数を利用し続けることを強くお勧めします:

Anyway, we strongly suggest to stick to the variables listed here:

1.

2.

3.

4.

5.

6.

7.

8.

response.title

response.subtitle

response.flash

response.menu

response.meta.author

response.meta.description

response.meta.keywords

response.meta.*

これにより、web2pyに同梱された標準の"layout.html"ファイルを、同じ変数セットを利用する別のレイアウトファイルに置き換えることが容易になります。

because this will make it easier for you to replace the standard "layout.html" file that comes with web2py with another layout file, one that uses the same set of variables.

古いバージョンのweb2pyはresponse.meta.authorの代わりにresponse.authorを用いていました。他のmeta属性も同様です。

Old versions of web2py user response.author instead of response.meta.author and similar for the other meta attributes.