... teView ¶ class TemplateView ¶ 属性 (とオプションのアクセサ): content_type extra_context http_method_names response_class [ render_to_response() ] template_engine template_name [ get_template_names() ] メソッド as_view() dispatch() get() get_context_dat ... a() head() http_method_not_allowed() render_to_response() setup() RedirectView ¶ class RedirectView ¶ 属性 (とオプションのアクセサ): http_method_names pattern_name pe ... name() ] extra_context http_method_names model pk_url_kwarg query_pk_and_slug queryset [ get_queryset() ] response_class [ render_to_response() ] slug_field [ get_slug_field() ] slug_url_kwarg template_engine template_name [ get_template_names() ] temp ... ... teView ¶ class TemplateView ¶ 属性 (とオプションのアクセサ): content_type extra_context http_method_names response_class [ render_to_response() ] template_engine template_name [ get_template_names() ] メソッド as_view() dispatch() get() get_context_dat ... a() head() http_method_not_allowed() render_to_response() setup() RedirectView ¶ class RedirectView ¶ 属性 (とオプションのアクセサ): http_method_names pattern_name pe ... name() ] extra_context http_method_names model pk_url_kwarg query_pk_and_slug queryset [ get_queryset() ] response_class [ render_to_response() ] slug_field [ get_slug_field() ] slug_url_kwarg template_engine template_name [ get_template_names() ] temp ... ... simple_tag を提供しています。 この関数は django.template.Library のメソッドで、任意の数の引数を受け取る関数を取り、それを render 関数と上記で説明した他の必要なビットにラップし、そしてテンプレートシステムに登録します。 私たちの current_time 関数は、以下 ... ime is {{ the_time }} . </ p > シンプル・ブロック・タグ ¶ django.template.Library. simple_block_tag () ¶ When a section of rendered template needs to be passed into a custom tag, Django provides the simple_block_tag helper function to accomplish this. ... o simple_tag() , this function accepts a custom tag function, but with the additional content argument, which contains the rendered content as defined inside the tag. This allows dynamic template sections to be easily incorporated into custom tags. たと ... ... simple_tag を提供しています。 この関数は django.template.Library のメソッドで、任意の数の引数を受け取る関数を取り、それを render 関数と上記で説明した他の必要なビットにラップし、そしてテンプレートシステムに登録します。 私たちの current_time 関数は、以下 ... ime is {{ the_time }} . </ p > シンプル・ブロック・タグ ¶ django.template.Library. simple_block_tag () ¶ When a section of rendered template needs to be passed into a custom tag, Django provides the simple_block_tag helper function to accomplish this. ... o simple_tag() , this function accepts a custom tag function, but with the additional content argument, which contains the rendered content as defined inside the tag. This allows dynamic template sections to be easily incorporated into custom tags. たと ... ... クト ¶ class SimpleTemplateResponse [ソース] ¶ 属性 ¶ SimpleTemplateResponse. template_name ¶ The name of the template to be rendered. Accepts a backend-dependent template object (such as those returned by get_template() ), the name of a template, or a l ... ンダリングするときに使用するコンテキストデータ。 これは dict でなければなりません。 例: {'foo': 123} SimpleTemplateResponse. rendered_content [ソース] ¶ 現在のテンプレートとコンテキストデータを使ってレンダリングされた、レスポンスコンテンツの現在の値。 Si ... mpleTemplateResponse. is_rendered [ソース] ¶ レスポンスの内容がレンダリングされたかどうかを示す真偽値。 メソッド ¶ SimpleTemplateResponse. __init__ ( temp ... ... クト ¶ class SimpleTemplateResponse [ソース] ¶ 属性 ¶ SimpleTemplateResponse. template_name ¶ The name of the template to be rendered. Accepts a backend-dependent template object (such as those returned by get_template() ), the name of a template, or a l ... ンダリングするときに使用するコンテキストデータ。 これは dict でなければなりません。 例: {'foo': 123} SimpleTemplateResponse. rendered_content [ソース] ¶ 現在のテンプレートとコンテキストデータを使ってレンダリングされた、レスポンスコンテンツの現在の値。 Si ... mpleTemplateResponse. is_rendered [ソース] ¶ レスポンスの内容がレンダリングされたかどうかを示す真偽値。 メソッド ¶ SimpleTemplateResponse. __init__ ( temp ... ... に一貫性を保ちやすくなっています。 TemplateResponseMixin Every built in view which returns a TemplateResponse will call the render_to_response() method that TemplateResponseMixin provides. Most of the time this will be called for you (for instance, it i ... ew ); similarly, it's unlikely that you'll need to override it, although if you want your response to return something not rendered via a Django template then you'll want to do it. For an example of this, see the JSONResponseMixin example . render_to_r ... フォルトを提供するためにこれをオーバーライドします。 ContextMixin Every built in view which needs context data, such as for rendering a template (including TemplateResponseMixin above), should call get_context_data() passing any data they want to ensure ... ... に一貫性を保ちやすくなっています。 TemplateResponseMixin Every built in view which returns a TemplateResponse will call the render_to_response() method that TemplateResponseMixin provides. Most of the time this will be called for you (for instance, it i ... ew ); similarly, it's unlikely that you'll need to override it, although if you want your response to return something not rendered via a Django template then you'll want to do it. For an example of this, see the JSONResponseMixin example . render_to_r ... フォルトを提供するためにこれをオーバーライドします。 ContextMixin Every built in view which needs context data, such as for rendering a template (including TemplateResponseMixin above), should call get_context_data() passing any data they want to ensure ... ... mplate ( "polls/index.html" ) context = { "latest_question_list" : latest_question_list } return HttpResponse ( template . render ( context , request )) このコードは、 polls/index.html というテンプレートをロードし、そこにコンテキストを渡します。コンテキ ... チュートリアルその2 で作った "What's up" という質問が入っていますね)。リンクは質問の詳細ページを指します。 ショートカット: render() ¶ テンプレートをロードしてコンテキストに値を入れ、テンプレートをレンダリングした結果を HttpResponse オブジェクトで返す、 ... ショートカットを提供します。これを使って index() ビューを書き換えてみましょう: polls/views.py ¶ from django.shortcuts import render from .models import Question def index ( request ): latest_question_list = Question . objects . order_by ( "-pub_date" )[: ... ... 関数やクラスは、便宜上、控えめな結合を取り入れます。 render() ¶ render ( request , template_name , context = None , content_type = None , status = None , using = None ) [ソース] ¶ 与 ... ction which returns a TemplateResponse because the constructor of TemplateResponse offers the same level of convenience as render() . 必須の引数 ¶ request このレスポンスを生成するのに使用されるリクエスト オブジェクト。 template_name 使用するテンプレート ... は、テンプレート myapp/index.html をMIMEタイプ application/xhtml+xml でレンダリングしてみます。 from django.shortcuts import render def my_view ( request ): # View code here... return render ( request , "myapp/index.html" , { "foo" : "bar" , }, content_t ... 2026年10月08日