{"title":"Base views","version":"1.9","locale":"ja","docname":"ref/class-based-views/base","url":"/ja/1.9/ref/class-based-views/base/","canonical":"https://djangodocs.dev/ja/1.9/ref/class-based-views/base/","summary":"The following three classes provide much of the functionality needed to create Django views.","html":"<h1>Base views<a class=\"heading-anchor\" href=\"#base-views\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>The following three classes provide much of the functionality needed to create\nDjango views. You may think of them as <em>parent</em> views, which can be used by\nthemselves or inherited from. They may not provide all the capabilities\nrequired for projects, in which case there are Mixins and Generic class-based\nviews.</p>\n<p>Many of Django's built-in class-based views inherit from other class-based\nviews or various mixins. Because this inheritance chain is very important, the\nancestor classes are  documented under the section title of <strong>Ancestors (MRO)</strong>.\nMRO is an acronym for Method Resolution Order.</p>\n<section id=\"view\">\n<h2><code class=\"docutils literal notranslate\">View</code><a class=\"heading-anchor\" href=\"#view\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.View\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-prename descclassname\">django.views.generic.base.</span><span class=\"sig-name descname\">View</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.View\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The master class-based base view. All other class-based views inherit from\nthis base class.</p>\n<p><strong>Method Flowchart</strong></p>\n<ol class=\"arabic simple\">\n<li><p><a class=\"reference internal\" href=\"#django.views.generic.base.View.dispatch\" title=\"django.views.generic.base.View.dispatch\"><code class=\"xref py py-meth docutils literal notranslate\">dispatch()</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#django.views.generic.base.View.http_method_not_allowed\" title=\"django.views.generic.base.View.http_method_not_allowed\"><code class=\"xref py py-meth docutils literal notranslate\">http_method_not_allowed()</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#django.views.generic.base.View.options\" title=\"django.views.generic.base.View.options\"><code class=\"xref py py-meth docutils literal notranslate\">options()</code></a></p></li>\n</ol>\n<p><strong>Example views.py</strong>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.http</span> <span class=\"kn\">import</span> HttpResponse\n<span class=\"kn\">from</span> <span class=\"nn\">django.views.generic</span> <span class=\"kn\">import</span> View\n\n<span class=\"k\">class</span> <span class=\"nc\">MyView</span><span class=\"p\">(</span>View<span class=\"p\">):</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">get</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> request<span class=\"p\">,</span> <span class=\"o\">*</span>args<span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<span class=\"p\">):</span>\n        <span class=\"k\">return</span> HttpResponse<span class=\"p\">(</span><span class=\"s1\">&#39;Hello, World!&#39;</span><span class=\"p\">)</span>\n</code></pre></div>\n<p><strong>Example urls.py</strong>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.conf.urls</span> <span class=\"kn\">import</span> url\n\n<span class=\"kn\">from</span> <span class=\"nn\">myapp.views</span> <span class=\"kn\">import</span> MyView\n\nurlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    url<span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^mine/$&#39;</span><span class=\"p\">,</span> MyView<span class=\"o\">.</span>as_view<span class=\"p\">(),</span> name<span class=\"o\">=</span><span class=\"s1\">&#39;my-view&#39;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p><strong>Attributes</strong></p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.View.http_method_names\">\n<span class=\"sig-name descname\">http_method_names</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.View.http_method_names\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The list of HTTP method names that this view will accept.</p>\n<p>Default:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"p\">[</span><span class=\"s1\">&#39;get&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;post&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;put&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;patch&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;delete&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;head&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;options&#39;</span><span class=\"p\">,</span> <span class=\"s1\">&#39;trace&#39;</span><span class=\"p\">]</span>\n</code></pre></div>\n</dd></dl>\n\n<p><strong>Methods</strong></p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.View.as_view\">\n<em class=\"property\"><span class=\"k\">classmethod</span> </em><span class=\"sig-name descname\">as_view</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">**</span>initkwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.View.as_view\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns a callable view that takes a request and returns a response:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code>response <span class=\"o\">=</span> MyView<span class=\"o\">.</span>as_view<span class=\"p\">()(</span>request<span class=\"p\">)</span>\n</code></pre></div>\n<aside class=\"version-note version-added\" data-version=\"1.9\" role=\"note\">\n<p class=\"version-note-title\">New in Django 1.9</p></aside>\n<p>The returned view has <code class=\"docutils literal notranslate\">view_class</code> and <code class=\"docutils literal notranslate\">view_initkwargs</code>\nattributes.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.View.dispatch\">\n<span class=\"sig-name descname\">dispatch</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">request</em>, <em class=\"sig-param\"><span class=\"o\">*</span>args</em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.View.dispatch\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The <code class=\"docutils literal notranslate\">view</code> part of the view -- the method that accepts a <code class=\"docutils literal notranslate\">request</code>\nargument plus arguments, and returns a HTTP response.</p>\n<p>The default implementation will inspect the HTTP method and attempt to\ndelegate to a method that matches the HTTP method; a <code class=\"docutils literal notranslate\">GET</code> will be\ndelegated to <code class=\"docutils literal notranslate\">get()</code>, a <code class=\"docutils literal notranslate\">POST</code> to <code class=\"docutils literal notranslate\">post()</code>, and so on.</p>\n<p>By default, a <code class=\"docutils literal notranslate\">HEAD</code> request will be delegated to <code class=\"docutils literal notranslate\">get()</code>.\nIf you need to handle <code class=\"docutils literal notranslate\">HEAD</code> requests in a different way than <code class=\"docutils literal notranslate\">GET</code>,\nyou can override the <code class=\"docutils literal notranslate\">head()</code> method. See\n<a class=\"reference internal\" href=\"/ja/1.9/topics/class-based-views/#supporting-other-http-methods\"><span class=\"std std-ref\">Supporting other HTTP methods</span></a> for an example.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.View.http_method_not_allowed\">\n<span class=\"sig-name descname\">http_method_not_allowed</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">request</em>, <em class=\"sig-param\"><span class=\"o\">*</span>args</em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.View.http_method_not_allowed\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>If the view was called with a HTTP method it doesn't support, this\nmethod is called instead.</p>\n<p>The default implementation returns <code class=\"docutils literal notranslate\">HttpResponseNotAllowed</code> with a\nlist of allowed methods in plain text.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.View.options\">\n<span class=\"sig-name descname\">options</span><span class=\"sig-paren\">(</span><em class=\"sig-param\">request</em>, <em class=\"sig-param\"><span class=\"o\">*</span>args</em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.View.options\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Handles responding to requests for the OPTIONS HTTP verb. Returns a\nresponse with the <code class=\"docutils literal notranslate\">Allow</code> header containing a list of the view's\nallowed HTTP method names.</p>\n</dd></dl>\n\n</dd></dl>\n\n</section>\n<section id=\"templateview\">\n<h2><code class=\"docutils literal notranslate\">TemplateView</code><a class=\"heading-anchor\" href=\"#templateview\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.TemplateView\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-prename descclassname\">django.views.generic.base.</span><span class=\"sig-name descname\">TemplateView</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.TemplateView\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Renders a given template, with the context containing parameters captured\nin the URL.</p>\n<p><strong>Ancestors (MRO)</strong></p>\n<p>This view inherits methods and attributes from the following views:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/ja/1.9/ref/class-based-views/mixins-simple/#django.views.generic.base.TemplateResponseMixin\" title=\"django.views.generic.base.TemplateResponseMixin\"><code class=\"xref py py-class docutils literal notranslate\">django.views.generic.base.TemplateResponseMixin</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ja/1.9/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin\" title=\"django.views.generic.base.ContextMixin\"><code class=\"xref py py-class docutils literal notranslate\">django.views.generic.base.ContextMixin</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#django.views.generic.base.View\" title=\"django.views.generic.base.View\"><code class=\"xref py py-class docutils literal notranslate\">django.views.generic.base.View</code></a></p></li>\n</ul>\n<p><strong>Method Flowchart</strong></p>\n<ol class=\"arabic simple\">\n<li><p><a class=\"reference internal\" href=\"#django.views.generic.base.View.dispatch\" title=\"django.views.generic.base.View.dispatch\"><code class=\"xref py py-meth docutils literal notranslate\">dispatch()</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#django.views.generic.base.View.http_method_not_allowed\" title=\"django.views.generic.base.View.http_method_not_allowed\"><code class=\"xref py py-meth docutils literal notranslate\">http_method_not_allowed()</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"/ja/1.9/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.get_context_data\" title=\"django.views.generic.base.ContextMixin.get_context_data\"><code class=\"xref py py-meth docutils literal notranslate\">get_context_data()</code></a></p></li>\n</ol>\n<p><strong>Example views.py</strong>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.views.generic.base</span> <span class=\"kn\">import</span> TemplateView\n\n<span class=\"kn\">from</span> <span class=\"nn\">articles.models</span> <span class=\"kn\">import</span> Article\n\n<span class=\"k\">class</span> <span class=\"nc\">HomePageView</span><span class=\"p\">(</span>TemplateView<span class=\"p\">):</span>\n\n    template_name <span class=\"o\">=</span> <span class=\"s2\">&quot;home.html&quot;</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">get_context_data</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<span class=\"p\">):</span>\n        context <span class=\"o\">=</span> <span class=\"nb\">super</span><span class=\"p\">(</span>HomePageView<span class=\"p\">,</span> <span class=\"bp\">self</span><span class=\"p\">)</span><span class=\"o\">.</span>get_context_data<span class=\"p\">(</span><span class=\"o\">**</span>kwargs<span class=\"p\">)</span>\n        context<span class=\"p\">[</span><span class=\"s1\">&#39;latest_articles&#39;</span><span class=\"p\">]</span> <span class=\"o\">=</span> Article<span class=\"o\">.</span>objects<span class=\"o\">.</span>all<span class=\"p\">()[:</span><span class=\"mi\">5</span><span class=\"p\">]</span>\n        <span class=\"k\">return</span> context\n</code></pre></div>\n<p><strong>Example urls.py</strong>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.conf.urls</span> <span class=\"kn\">import</span> url\n\n<span class=\"kn\">from</span> <span class=\"nn\">myapp.views</span> <span class=\"kn\">import</span> HomePageView\n\nurlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    url<span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^$&#39;</span><span class=\"p\">,</span> HomePageView<span class=\"o\">.</span>as_view<span class=\"p\">(),</span> name<span class=\"o\">=</span><span class=\"s1\">&#39;home&#39;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p><strong>Context</strong></p>\n<ul class=\"simple\">\n<li><p>Populated (through <a class=\"reference internal\" href=\"/ja/1.9/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin\" title=\"django.views.generic.base.ContextMixin\"><code class=\"xref py py-class docutils literal notranslate\">ContextMixin</code></a>) with\nthe keyword arguments captured from the URL pattern that served the view.</p></li>\n</ul>\n</dd></dl>\n\n</section>\n<section id=\"redirectview\">\n<h2><code class=\"docutils literal notranslate\">RedirectView</code><a class=\"heading-anchor\" href=\"#redirectview\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<dl class=\"py class\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.RedirectView\">\n<em class=\"property\"><span class=\"k\">class</span> </em><span class=\"sig-prename descclassname\">django.views.generic.base.</span><span class=\"sig-name descname\">RedirectView</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.RedirectView\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Redirects to a given URL.</p>\n<p>The given URL may contain dictionary-style string formatting, which will be\ninterpolated against the parameters captured in the URL. Because keyword\ninterpolation is <em>always</em> done (even if no arguments are passed in), any\n<code class=\"docutils literal notranslate\">&quot;%&quot;</code> characters in the URL must be written as <code class=\"docutils literal notranslate\">&quot;%%&quot;</code> so that Python\nwill convert them to a single percent sign on output.</p>\n<p>If the given URL is <code class=\"docutils literal notranslate\">None</code>, Django will return an <code class=\"docutils literal notranslate\">HttpResponseGone</code>\n(410).</p>\n<p><strong>Ancestors (MRO)</strong></p>\n<p>This view inherits methods and attributes from the following view:</p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"#django.views.generic.base.View\" title=\"django.views.generic.base.View\"><code class=\"xref py py-class docutils literal notranslate\">django.views.generic.base.View</code></a></p></li>\n</ul>\n<p><strong>Method Flowchart</strong></p>\n<ol class=\"arabic simple\">\n<li><p><a class=\"reference internal\" href=\"#django.views.generic.base.View.dispatch\" title=\"django.views.generic.base.View.dispatch\"><code class=\"xref py py-meth docutils literal notranslate\">dispatch()</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#django.views.generic.base.View.http_method_not_allowed\" title=\"django.views.generic.base.View.http_method_not_allowed\"><code class=\"xref py py-meth docutils literal notranslate\">http_method_not_allowed()</code></a></p></li>\n<li><p><a class=\"reference internal\" href=\"#django.views.generic.base.RedirectView.get_redirect_url\" title=\"django.views.generic.base.RedirectView.get_redirect_url\"><code class=\"xref py py-meth docutils literal notranslate\">get_redirect_url()</code></a></p></li>\n</ol>\n<p><strong>Example views.py</strong>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.shortcuts</span> <span class=\"kn\">import</span> get_object_or_404\n<span class=\"kn\">from</span> <span class=\"nn\">django.views.generic.base</span> <span class=\"kn\">import</span> RedirectView\n\n<span class=\"kn\">from</span> <span class=\"nn\">articles.models</span> <span class=\"kn\">import</span> Article\n\n<span class=\"k\">class</span> <span class=\"nc\">ArticleCounterRedirectView</span><span class=\"p\">(</span>RedirectView<span class=\"p\">):</span>\n\n    permanent <span class=\"o\">=</span> <span class=\"kc\">False</span>\n    query_string <span class=\"o\">=</span> <span class=\"kc\">True</span>\n    pattern_name <span class=\"o\">=</span> <span class=\"s1\">&#39;article-detail&#39;</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">get_redirect_url</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">,</span> <span class=\"o\">*</span>args<span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<span class=\"p\">):</span>\n        article <span class=\"o\">=</span> get_object_or_404<span class=\"p\">(</span>Article<span class=\"p\">,</span> pk<span class=\"o\">=</span>kwargs<span class=\"p\">[</span><span class=\"s1\">&#39;pk&#39;</span><span class=\"p\">])</span>\n        article<span class=\"o\">.</span>update_counter<span class=\"p\">()</span>\n        <span class=\"k\">return</span> <span class=\"nb\">super</span><span class=\"p\">(</span>ArticleCounterRedirectView<span class=\"p\">,</span> <span class=\"bp\">self</span><span class=\"p\">)</span><span class=\"o\">.</span>get_redirect_url<span class=\"p\">(</span><span class=\"o\">*</span>args<span class=\"p\">,</span> <span class=\"o\">**</span>kwargs<span class=\"p\">)</span>\n</code></pre></div>\n<p><strong>Example urls.py</strong>:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"kn\">from</span> <span class=\"nn\">django.conf.urls</span> <span class=\"kn\">import</span> url\n<span class=\"kn\">from</span> <span class=\"nn\">django.views.generic.base</span> <span class=\"kn\">import</span> RedirectView\n\n<span class=\"kn\">from</span> <span class=\"nn\">article.views</span> <span class=\"kn\">import</span> ArticleCounterRedirectView<span class=\"p\">,</span> ArticleDetail\n\nurlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    url<span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^counter/(?P&lt;pk&gt;[0-9]+)/$&#39;</span><span class=\"p\">,</span> ArticleCounterRedirectView<span class=\"o\">.</span>as_view<span class=\"p\">(),</span> name<span class=\"o\">=</span><span class=\"s1\">&#39;article-counter&#39;</span><span class=\"p\">),</span>\n    url<span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^details/(?P&lt;pk&gt;[0-9]+)/$&#39;</span><span class=\"p\">,</span> ArticleDetail<span class=\"o\">.</span>as_view<span class=\"p\">(),</span> name<span class=\"o\">=</span><span class=\"s1\">&#39;article-detail&#39;</span><span class=\"p\">),</span>\n    url<span class=\"p\">(</span><span class=\"sa\">r</span><span class=\"s1\">&#39;^go-to-django/$&#39;</span><span class=\"p\">,</span> RedirectView<span class=\"o\">.</span>as_view<span class=\"p\">(</span>url<span class=\"o\">=</span><span class=\"s1\">&#39;https://djangoproject.com&#39;</span><span class=\"p\">),</span> name<span class=\"o\">=</span><span class=\"s1\">&#39;go-to-django&#39;</span><span class=\"p\">),</span>\n<span class=\"p\">]</span>\n</code></pre></div>\n<p><strong>Attributes</strong></p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.RedirectView.url\">\n<span class=\"sig-name descname\">url</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.RedirectView.url\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The URL to redirect to, as a string. Or <code class=\"docutils literal notranslate\">None</code> to raise a 410 (Gone)\nHTTP error.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.RedirectView.pattern_name\">\n<span class=\"sig-name descname\">pattern_name</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.RedirectView.pattern_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name of the URL pattern to redirect to. Reversing will be done\nusing the same args and kwargs as are passed in for this view.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.RedirectView.permanent\">\n<span class=\"sig-name descname\">permanent</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.RedirectView.permanent\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Whether the redirect should be permanent. The only difference here is\nthe HTTP status code returned. If <code class=\"docutils literal notranslate\">True</code>, then the redirect will use\nstatus code 301. If <code class=\"docutils literal notranslate\">False</code>, then the redirect will use status code\n302. By default, <code class=\"docutils literal notranslate\">permanent</code> is <code class=\"docutils literal notranslate\">False</code>.</p>\n<aside class=\"version-note version-changed\" data-version=\"1.9\" role=\"note\">\n<p class=\"version-note-title\">Changed in Django 1.9</p><p>The default value of the <code class=\"docutils literal notranslate\">permanent</code> attribute changed from\n<code class=\"docutils literal notranslate\">True</code> to <code class=\"docutils literal notranslate\">False</code>.</p>\n</aside>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.RedirectView.query_string\">\n<span class=\"sig-name descname\">query_string</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.RedirectView.query_string\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Whether to pass along the GET query string to the new location. If\n<code class=\"docutils literal notranslate\">True</code>, then the query string is appended to the URL. If <code class=\"docutils literal notranslate\">False</code>,\nthen the query string is discarded. By default, <code class=\"docutils literal notranslate\">query_string</code> is\n<code class=\"docutils literal notranslate\">False</code>.</p>\n</dd></dl>\n\n<p><strong>Methods</strong></p>\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.RedirectView.get_redirect_url\">\n<span class=\"sig-name descname\">get_redirect_url</span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\">*</span>args</em>, <em class=\"sig-param\"><span class=\"o\">**</span>kwargs</em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.base.RedirectView.get_redirect_url\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Constructs the target URL for redirection.</p>\n<p>The default implementation uses <a class=\"reference internal\" href=\"#django.views.generic.base.RedirectView.url\" title=\"django.views.generic.base.RedirectView.url\"><code class=\"xref py py-attr docutils literal notranslate\">url</code></a> as a starting\nstring and performs expansion of <code class=\"docutils literal notranslate\">%</code> named parameters in that string\nusing the named groups captured in the URL.</p>\n<p>If <a class=\"reference internal\" href=\"#django.views.generic.base.RedirectView.url\" title=\"django.views.generic.base.RedirectView.url\"><code class=\"xref py py-attr docutils literal notranslate\">url</code></a> is not set, <code class=\"docutils literal notranslate\">get_redirect_url()</code> tries to reverse the\n<a class=\"reference internal\" href=\"#django.views.generic.base.RedirectView.pattern_name\" title=\"django.views.generic.base.RedirectView.pattern_name\"><code class=\"xref py py-attr docutils literal notranslate\">pattern_name</code></a> using what was captured in the URL (both named and\nunnamed groups are used).</p>\n<p>If requested by <a class=\"reference internal\" href=\"#django.views.generic.base.RedirectView.query_string\" title=\"django.views.generic.base.RedirectView.query_string\"><code class=\"xref py py-attr docutils literal notranslate\">query_string</code></a>, it will also append the query\nstring to the generated URL.\nSubclasses may implement any behavior they wish, as long as the method\nreturns a redirect-ready URL string.</p>\n</dd></dl>\n\n</dd></dl>\n\n</section>","rootId":"base-views","toc":[{"title":"View","anchor":"view","children":[]},{"title":"TemplateView","anchor":"templateview","children":[]},{"title":"RedirectView","anchor":"redirectview","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/ja/1.9/ref/"},{"docname":"ref/class-based-views/index","title":"Built-in class-based views API","url":"/ja/1.9/ref/class-based-views/"}],"prev":{"docname":"ref/class-based-views/index","title":"Built-in class-based views API","url":"/ja/1.9/ref/class-based-views/"},"next":{"docname":"ref/class-based-views/generic-display","title":"Generic display views","url":"/ja/1.9/ref/class-based-views/generic-display/"},"formats":{"html":"/ja/1.9/ref/class-based-views/base/","markdown":"/ja/1.9/ref/class-based-views/base.md","json":"/ja/1.9/ref/class-based-views/base.json"},"source":"https://github.com/django/django/blob/stable/1.9.x/docs/ref/class-based-views/base.txt","official":"https://docs.djangoproject.com/ja/1.9/ref/class-based-views/base/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0","1.11","1.10","1.9"],"inLocales":["en","fr","ja","id","pt-br","es"]}