... シンプルなジェネリックビュー View class View 属性 (とオプションのアクセサ): http_method_names メソッド as_view() dispatch() head() http_method_not_allowed() setup() TemplateView class TemplateView 属性 (とオプションのアクセサ): content_type extra_cont ... response() ] template_engine template_name [ get_template_names() ] メソッド as_view() dispatch() get() get_context_data() head() http_method_not_allowed() render_to_response() setup() RedirectView class RedirectView 属性 (とオプションのアクセサ): ht ... p_method_names pattern_name permanent query_string url [ get_redirect_url() ] メソッド as_view() delete() dispatch() get() head() http_method_not_allowed() options() post() put() setup() 詳細ビュー DetailView class DetailView 属性 (とオプションのアク ... ... g PRNumber and TicketNumber with the actual pull request and Trac ticket numbers: / $ git fetch upstream pull/PRNumber/head:ticket_TicketNumber $ git checkout ticket_TicketNumber $ git push origin ticket_TicketNumber ...\> git fetch upstream pull ... /PRNumber/head:ticket_TicketNumber ...\> git checkout ticket_TicketNumber ...\> git push origin ticket_TicketNumber For example, to conti ... nue PR 8000 for ticket 123, run: / $ git fetch upstream pull/8000/head:ticket_123 $ git checkout ticket_123 $ git push origin ticket_123 ...\> git fetch upstream pull/8000/head:ticket_123 ...\> ... ... commit, use the "reword" option in interactive rebase. For example, to reword one of the last three commits: git rebase -i HEAD~3 This opens an editor listing the three commits, each prefixed with the word "pick". Change "pick" to "reword" (or "r") o ... work. To rework the history of your branch you can squash the commits into one by using interactive rebase: git rebase -i HEAD~2 The HEAD~2 above is shorthand for two latest commits. The above command will open an editor showing the two commits, pre ... "edit" option in rebase. This way you can change a single commit, for example to fix a typo in a docstring: git rebase -i HEAD~3 # Choose edit, pick, pick for the commits # Now you are able to rework the commit (use git add normally to add changes) ... ... す。 require_POST () ビューがPOSTメソッドのみを受け付けるようにするデコレータです。 require_safe () ビューが GET メソッドと HEAD メソッドのみを受け付けるようにするデコレータです。これらのメソッドは、要求されたリソースを取得する以外の動作をする意図を持 ... たないので、一般的に "安全である" と考えられています。 注釈 Webサーバーは、ヘッダーを変更せずに、レスポンスのコンテンツをHEADリクエストから自動的に削除するべきです。そのため、ビューではHEADリクエストをGETリクエストとまったく同じように処理できます。リ ... ンクチェッカーなどの一部のソフトウェアはHEADリクエストに依存しているため、 require_GET の代わりに require_safe を使用することをお勧めします。 条件付きのビュー処理 djang ... ... es このビューが受け入れる HTTP メソッドの名称のリストです。 デフォルト値: [ "get" , "post" , "put" , "patch" , "delete" , "head" , "options" , "trace" ] メソッド classmethod as_view ( ** initkwargs ) リクエストを受け取ってレスポンスを返す、呼び出し可 ... ドと一致するメソッドに処理を委ねるよう試みます。例えば、 GET は get() に、 POST は post() に委ねられます。 デフォルトでは、 HEAD リクエストは get() に委ねられます。 HEAD リクエストを GET とは違う方法で操作する必要がある場合は、 head() メソッドをオーバ ... ドが呼び出されます。 The default implementation returns HttpResponseNotAllowed with the list of allowed methods in the Allow header, as required by RFC 7231 . The response body is empty. options ( request , * args , ** kwargs ) OPTIONS HTTP 動詞のための ... ... 使用して ETag ヘッダを設定してもらうこともできます。 When the client next requests the same resource, it might send along a header such as either If-Modified-Since or If-Unmodified-Since , containing the date of the last modification time it was sent, ... 04 status code can be sent back, instead of a full response, telling the client that nothing has changed. Depending on the header, if the page has been modified or does not match the ETag sent by the client, a 412 status code (Precondition Failed) ma ... べきです。 デコレータは、それらがビューによってまだ設定されていない場合、そしてリクエストのメソッドが安全なもの( GET または HEAD )である場合に、レスポンスに ETag ヘッダと Last-Modified ヘッダを設定します。 この機能を有効に使う方法は、例を挙げて説明す ... ... from django.views.generic import ListView from books.models import Book class BookListView ( ListView ): model = Book def head ( self , * args , ** kwargs ): last_book = self . get_queryset () . latest ( "publication_date" ) response = HttpResponse ... ( # RFC 1123 date format. headers = { "Last-Modified" : last_book . publication_date . strftime ( " %a , %d %b %Y %H:%M:%S GMT" ) }, ) return response If ... a GET request, an object list is returned in the response (using the book_list.html template). But if the client issues a HEAD request, the response has an empty body and the Last-Modified header indicates when the most recent book was published. Ba ... ... > {{ section.title }} </ h1 > {% for story in story_list %} < h2 > < a href = " {{ story.get_absolute_url }} " > {{ story.headline | upper }} </ a > </ h2 > < p > {{ story.tease | truncatewords :"100" }} </ p > {% endfor %} {% endblock %} 設計思想 な ... バーライドさせることができます。 テンプレートの継承について、まず例を見てみましょう: <!DOCTYPE html> < html lang = "en" > < head > < link rel = "stylesheet" href = "style.css" > < title > {% block title %} My amazing site {% endblock %} </ title > </ ... テンツと差し替えます。 blog_entries の値に応じて、アウトプットは以下のようになります: <!DOCTYPE html> < html lang = "en" > < head > < link rel = "stylesheet" href = "style.css" > < title > My amazing blog </ title > </ head > < body > < div id = "sideb ... ... th = 70 ) def __str__ ( self ): return self . full_name class Article ( models . Model ): pub_date = models . DateField () headline = models . CharField ( max_length = 200 ) content = models . TextField () reporter = models . ForeignKey ( Reporter , ... on_delete = models . CASCADE ) def __str__ ( self ): return self . headline モデルのインストール 次に、データベーステーブルを自動で作成する Django のコマンドラインユーティリティを実行します。 / ... query does not exist. # Create an article. >>> from datetime import date >>> a = Article ( ... pub_date = date . today (), headline = "Django is cool" , content = "Yeah." , reporter = r ... ) >>> a . save () # Now the article is in the database. >>> ... ... キスト変数が渡されます。 以下は、サンプルの flatpages/default.html テンプレートです: <!DOCTYPE html> < html lang = "en" > < head > < title > {{ flatpage.title }} </ title > </ head > < body > {{ flatpage.content }} </ body > </ html > フラットページの ... 2026年10月08日