HTTPリクエストの戸田の内容を取得する方法を解説します。
HttpRequest.methodで取得できます。
if request.method == 'GET':
# GETのときの処理
…
if request.method == 'POST':
# POSTのときの処理
…
HttpRequest.pathでリクエストされたパス文字列を取得できます。
request.path #=> /bbs/entry/1
HttpRequest.get_full_path()は、pathとクエリ文字列を返します。
request.get_full_path() #=> /bbs/entry/1?print=true
HttpRequest.get_host()はリクエストの送信元を返します。
request.get_host() #=> 127.0.0.1:8000
HttpRequest.METAは、利用できるすべてのHTTPヘッダが入った辞書オブジェクトです。
request.META['HTTP_USER_AGENT'] #=> ユーザーエージェント