... スのヒエラルキーがわかりやすく紹介されています。 シンプルなジェネリックビュー View class View 属性 (とオプションのアクセサ): http_method_names メソッド as_view() dispatch() head() http_method_not_allowed() setup() TemplateView class TemplateView 属性 ( ... とオプションのアクセサ): content_type extra_context http_method_names response_class [ render_to_response() ] template_engine template_name [ get_template_names() ] メソッド as_vi ... ew() dispatch() get() get_context_data() head() http_method_not_allowed() render_to_response() setup() RedirectView class RedirectView 属性 (とオプションのアクセサ): http_meth ... ... オブジェクトを生成します。それから Django は HttpRequest をビュー関数の最初の関数として渡し、適切なビューを読み込みます。あらゆるビューは HttpResponse オブジェクトを返す必要 ... があります。 このドキュメントでは、 HttpRequest と HttpResponse オブジェクトの API を説明しています。これは django.http モジュールにて定義されています。 HttpReques ... t オブジェクト class HttpRequest [ソース] 属性 特に記載がない限り、全ての属性は読み取り専用だと考えてください。 HttpRequest. scheme [ソース] リクエス ... ... S, django.http.HttpRequest.scheme would incorrectly detect client requests made via HTTP as using HTTPS. This entails incorrect results f ... or is_secure() , and build_absolute_uri() , and that HTTP requests would not be redirected to HTTPS in accordance with SECURE_SSL_REDIRECT . HttpRequest.scheme now respects SECURE_ ... PROXY_SSL_HEADER , if it is configured, and the appropriate header is set on the request, for both HTTP and HTTPS requests. If you deploy Django behind a reverse-proxy that forwards HTTP requests, and that connects to Django v ... ... jango.http.HttpRequest.scheme would incorrectly detect client requests made via HTTP as using HTTPS. This entails incorrect results f ... or is_secure() , and build_absolute_uri() , and that HTTP requests would not be redirected to HTTPS in accordance with SECURE_SSL_REDIRECT . HttpRequest.scheme now respects SECURE_ ... PROXY_SSL_HEADER , if it is configured, and the appropriate header is set on the request, for both HTTP and HTTPS requests. If you deploy Django behind a reverse-proxy that forwards HTTP requests, and that connects to Django v ... ... ジェネリックビューではないので、 django.views からインポートすることもできます。 メソッドのフローチャート setup() dispatch() http_method_not_allowed() options() Example views.py : from django.http import HttpResponse from django.views import View class ... MyView ( View ): def get ( self , request , * args , ** kwargs ): return HttpResponse ( "Hello, World!" ) Example urls.py : from django.urls import path from myapp.views import MyView urlpatterns = [ ... path ( "mine/" , MyView . as_view (), name = "my-view" ), ] 属性 http_method_names このビューが受け入れる HTTP メソッドの名称のリストです。 デフォルト値: [ "get" , "post" , "put" , "patch" , " ... ... ting via HTTPS When deployed behind a reverse-proxy connecting to Django via HTTPS, django.http.HttpRequest.scheme would incorrectly det ... ect client requests made via HTTP as using HTTPS. This entails incorrect results for is_secure() , and build_absolute_uri() , and that HTTP requests would n ... ot be redirected to HTTPS in accordance with SECURE_SSL_REDIRECT . HttpRequest.scheme now respects SECURE_PROXY_SSL_HEADER , if it is configured, a ... ... ngo, this value is made available in request.META (as REMOTE_USER when supplied as an environment variable, as in WSGI, or HTTP_REMOTE_USER when supplied via an HTTP header, as in ASGI). Django can be configured to make use of the REMOTE_USER value u ... ckend" , ] With this setup, RemoteUserMiddleware will detect the username in request.META['REMOTE_USER'] (or request.META['HTTP_REMOTE_USER'] under ASGI) and will authenticate and auto-login that user using the RemoteUserBackend . この特定の設定は、デ ... せん。許可したい場合は、 AllowAllUsersRemoteUserBackend を使用してください。 If your authentication mechanism uses a custom HTTP header and not REMOTE_USER , you can subclass RemoteUserMiddleware and set the header attribute to the desired request.MET ... ... ータを送信するのを回避するためによく使われます。しかし、同じヘッダーは、全ての HTTP メソッド ( POST 、 PUT 、 DELETE など) で利用できます。 Django がビューから送り返す各ページ (レスポンス) に対して、Django ... は2種類の HTTP ヘッダ、 ETag ヘッダと Last-Modified ヘッダを提供できます。これらのヘッダは HTTP レスポンス上ではオプションです。ヘッダはビ ... アントに対して、コンテンツが前回のリクエスト以降変更されていないことを伝えます。 これら 2 つの関数は django.views.decorators.http.condition デコレータのパラメータとして渡されます。このデコレータは、HTTP リクエストのヘッダがリソースのヘッダと一致するかど ... ... ァイルにビューを記述します。 シンプルなビュー 以下は、HTML ドキュメントとして、現在の日付と時刻を返すビューです: from django.http import HttpResponse import datetime def current_datetime ( request ): now = datetime . datetime . now () html = '<html lan ... g="en"><body>It is now %s .</body></html>' % now return HttpResponse ( html ) 1 行ずつコードを見ていきましょう: 最初に、Python の datetime ライブラリ とともに、クラス HttpResponse を ... django.http モジュールからインポートします。 次に、 current_datetime という関数を定義します。これがビュー関数です。それぞれのビュー関数 ... ... ください。 特定のHTTPメソッドのみ許可する django.views.decorators.http にあるデコレータを使用することで、リクエストメソッドに基づいてビューへのア ... クセスを制限できます。アクセスが制限されるとき、これらのデコレータは django.http.HttpResponseNotAllowed を返します。 require_http_methods ( request_method_list ) [ソース] ビューが特定のリクエストメソッド ... のみを受け付けるようにするデコレータです。以下のように使います。 from django.views.decorators.http import require_http_methods @require_http_methods ([ "GET" , "POST" ]) def my_view ( request ): # I can assume now that on ... 2026年10月08日