{"title":"Base views","version":"5.0","locale":"ko","docname":"ref/class-based-views/base","url":"/ko/5.0/ref/class-based-views/base/","canonical":"https://djangodocs.dev/ko/5.0/ref/class-based-views/base/","summary":"다음 세 가지 클래스는 Django 뷰를 만드는 데 필요한 많은 기능을 제공합니다. 사용자가 직접 사용하거나 상속할 수 있는 parent 뷰로 생각할 수 있습니다.","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>다음 세 가지 클래스는 Django 뷰를 만드는 데 필요한 많은 기능을 제공합니다. 사용자가 직접 사용하거나 상속할 수 있는 <em>parent</em> 뷰로 생각할 수 있습니다. 프로젝트에 필요한 모든 기능을 제공하지 못할 수 있습니다. 이 경우 Mixins 및 Generic class-based view가 있습니다.</p>\n<p>Django의 기본 제공 클래스 기반 뷰 중 많은 것이 다른 클래스 기반 뷰 또는 다양한 믹스인에서 상속됩니다. 이 상속 체인은 매우 중요하기 때문에 상위 클래스는 <strong>Ancestors (MRO)</strong> 섹션 제목으로 문서화되어 있습니다. MRO는 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>기본 뷰 클래스입니다. 다른 모든 클래스 기반 뷰는 이 기본 클래스에서 상속됩니다. 그것은 엄밀히 말하면 일반적인 견해가 아니기 때문에 <a href=\"#id1\"><span class=\"problematic\" id=\"id2\">``</span></a>django.views``에서 가져올 수도 있습니다.</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.setup\" title=\"django.views.generic.base.View.setup\"><code class=\"xref py py-meth docutils literal notranslate\">setup()</code></a></p></li>\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</span> <span class=\"kn\">import</span> View\n\n\n<span class=\"k\">class</span> <span class=\"nc\">MyView</span><span class=\"p\">(</span>View<span class=\"p\">):</span>\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=\"s2\">&quot;Hello, World!&quot;</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.urls</span> <span class=\"kn\">import</span> path\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    path<span class=\"p\">(</span><span class=\"s2\">&quot;mine/&quot;</span><span class=\"p\">,</span> MyView<span class=\"o\">.</span>as_view<span class=\"p\">(),</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;my-view&quot;</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>이 뷰에서 허용할 HTTP 메서드 이름 목록입니다.</p>\n<p>기본:</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=\"s2\">&quot;get&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;post&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;put&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;patch&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;delete&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;head&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;options&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;trace&quot;</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>요청을 받고 응답을 반환하는 호출 가능 보기를 반환합니다:</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<p>반환된 뷰는 <code class=\"docutils literal notranslate\">view_class</code> 및 <code class=\"docutils literal notranslate\">view_initkwargs</code> 속성을 가지고 있습니다.</p>\n<p>요청/응답 주기 동안 뷰가 호출되면 <code class=\"xref py py-meth docutils literal notranslate\">setup`메소드는 뷰의 &quot;request&quot; 속성에&#160; :class:`~django.http.HttpRequest`를 할당하고 모든 위치 및/또는 키워드 argument :ref:`captured from the URL pattern &lt;how-django-processes-a-request&gt;를 각각 ``args`()</code> 및 <code class=\"docutils literal notranslate\">kwargs</code> 속성에 할당합니다. 그러면 :meth:<a href=\"#id1\"><span class=\"problematic\" id=\"id2\">`</span></a>dispatch`가 호출됩니다.</p>\n<p>If a <code class=\"docutils literal notranslate\">View</code> subclass defines asynchronous (<code class=\"docutils literal notranslate\">async def</code>) method\nhandlers, <code class=\"docutils literal notranslate\">as_view()</code> will mark the returned callable as a coroutine\nfunction. An <code class=\"docutils literal notranslate\">ImproperlyConfigured</code> exception will be raised if both\nasynchronous (<code class=\"docutils literal notranslate\">async def</code>) and synchronous (<code class=\"docutils literal notranslate\">def</code>) handlers are\ndefined on a single view-class.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.base.View.setup\">\n<span class=\"sig-name descname\">setup</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.setup\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Performs key view initialization prior to <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>\n<p>If overriding this method, you must call <code class=\"docutils literal notranslate\">super()</code>.</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 an 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=\"/ko/5.0/topics/class-based-views/#supporting-other-http-methods\"><span class=\"std std-ref\">다른 HTTP 메소드 지원</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 an 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<p>If the other HTTP methods handlers on the class are asynchronous\n(<code class=\"docutils literal notranslate\">async def</code>) then the response will be wrapped in a coroutine\nfunction for use with <code class=\"docutils literal notranslate\">await</code>.</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=\"/ko/5.0/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=\"/ko/5.0/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.setup\" title=\"django.views.generic.base.View.setup\"><code class=\"xref py py-meth docutils literal notranslate\">setup()</code></a></p></li>\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=\"/ko/5.0/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\n<span class=\"k\">class</span> <span class=\"nc\">HomePageView</span><span class=\"p\">(</span>TemplateView<span class=\"p\">):</span>\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><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=\"s2\">&quot;latest_articles&quot;</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.urls</span> <span class=\"kn\">import</span> path\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    path<span class=\"p\">(</span><span class=\"s2\">&quot;&quot;</span><span class=\"p\">,</span> HomePageView<span class=\"o\">.</span>as_view<span class=\"p\">(),</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;home&quot;</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=\"/ko/5.0/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<li><p>You can also add context using the\n<a class=\"reference internal\" href=\"/ko/5.0/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.extra_context\" title=\"django.views.generic.base.ContextMixin.extra_context\"><code class=\"xref py py-attr docutils literal notranslate\">extra_context</code></a> keyword\nargument for <a class=\"reference internal\" href=\"#django.views.generic.base.View.as_view\" title=\"django.views.generic.base.View.as_view\"><code class=\"xref py py-meth docutils literal notranslate\">as_view()</code></a>.</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.setup\" title=\"django.views.generic.base.View.setup\"><code class=\"xref py py-meth docutils literal notranslate\">setup()</code></a></p></li>\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\n<span class=\"k\">class</span> <span class=\"nc\">ArticleCounterRedirectView</span><span class=\"p\">(</span>RedirectView<span class=\"p\">):</span>\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=\"s2\">&quot;article-detail&quot;</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=\"s2\">&quot;pk&quot;</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><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.urls</span> <span class=\"kn\">import</span> path\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> ArticleDetailView\n\nurlpatterns <span class=\"o\">=</span> <span class=\"p\">[</span>\n    path<span class=\"p\">(</span>\n        <span class=\"s2\">&quot;counter/&lt;int:pk&gt;/&quot;</span><span class=\"p\">,</span>\n        ArticleCounterRedirectView<span class=\"o\">.</span>as_view<span class=\"p\">(),</span>\n        name<span class=\"o\">=</span><span class=\"s2\">&quot;article-counter&quot;</span><span class=\"p\">,</span>\n    <span class=\"p\">),</span>\n    path<span class=\"p\">(</span><span class=\"s2\">&quot;details/&lt;int:pk&gt;/&quot;</span><span class=\"p\">,</span> ArticleDetailView<span class=\"o\">.</span>as_view<span class=\"p\">(),</span> name<span class=\"o\">=</span><span class=\"s2\">&quot;article-detail&quot;</span><span class=\"p\">),</span>\n    path<span class=\"p\">(</span>\n        <span class=\"s2\">&quot;go-to-django/&quot;</span><span class=\"p\">,</span>\n        RedirectView<span class=\"o\">.</span>as_view<span class=\"p\">(</span>url<span class=\"o\">=</span><span class=\"s2\">&quot;https://www.djangoproject.com/&quot;</span><span class=\"p\">),</span>\n        name<span class=\"o\">=</span><span class=\"s2\">&quot;go-to-django&quot;</span><span class=\"p\">,</span>\n    <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</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>리다이렉션을 위한 타겟 URL을 생성합니다.</p>\n<p>The <code class=\"docutils literal notranslate\">args</code> and <code class=\"docutils literal notranslate\">kwargs</code> arguments are positional and/or keyword\narguments <a class=\"reference internal\" href=\"/ko/5.0/topics/http/urls/#how-django-processes-a-request\"><span class=\"std std-ref\">captured from the URL pattern</span></a>, respectively.</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 레퍼런스","url":"/ko/5.0/ref/"},{"docname":"ref/class-based-views/index","title":"Built-in class-based views API","url":"/ko/5.0/ref/class-based-views/"}],"prev":{"docname":"ref/class-based-views/index","title":"Built-in class-based views API","url":"/ko/5.0/ref/class-based-views/"},"next":{"docname":"ref/class-based-views/generic-display","title":"Generic display views","url":"/ko/5.0/ref/class-based-views/generic-display/"},"formats":{"html":"/ko/5.0/ref/class-based-views/base/","markdown":"/ko/5.0/ref/class-based-views/base.md","json":"/ko/5.0/ref/class-based-views/base.json"},"source":"https://github.com/django/django/blob/stable/5.0.x/docs/ref/class-based-views/base.txt","official":"https://docs.djangoproject.com/ko/5.0/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"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}