{"title":"Single object mixins","version":"4.0","locale":"en","docname":"ref/class-based-views/mixins-single-object","url":"/en/4.0/ref/class-based-views/mixins-single-object/","canonical":"https://djangodocs.dev/en/4.0/ref/class-based-views/mixins-single-object/","summary":"SingleObjectMixin Link to this heading # class django.views.generic.detail. SingleObjectMixin Link to this definition # Provides a mechanism for looking up an…","html":"<h1>Single object mixins<a class=\"heading-anchor\" href=\"#single-object-mixins\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<section id=\"singleobjectmixin\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">SingleObjectMixin</span></code><a class=\"heading-anchor\" href=\"#singleobjectmixin\"><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.detail.SingleObjectMixin\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-prename descclassname\"><span class=\"pre\">django.views.generic.detail.</span></span><span class=\"sig-name descname\"><span class=\"pre\">SingleObjectMixin</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Provides a mechanism for looking up an object associated with the\ncurrent HTTP request.</p>\n<p><strong>Methods and Attributes</strong></p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.model\">\n<span class=\"sig-name descname\"><span class=\"pre\">model</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.model\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The model that this view will display data for. Specifying <code class=\"docutils literal notranslate\"><span class=\"pre\">model</span>\n<span class=\"pre\">=</span> <span class=\"pre\">Foo</span></code> is effectively the same as specifying <code class=\"docutils literal notranslate\"><span class=\"pre\">queryset</span> <span class=\"pre\">=</span>\n<span class=\"pre\">Foo.objects.all()</span></code>, where <code class=\"docutils literal notranslate\"><span class=\"pre\">objects</span></code> stands for <code class=\"docutils literal notranslate\"><span class=\"pre\">Foo</span></code>’s\n<a class=\"reference internal\" href=\"/en/4.0/topics/db/managers/#default-managers\"><span class=\"std std-ref\">default manager</span></a>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.queryset\">\n<span class=\"sig-name descname\"><span class=\"pre\">queryset</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.queryset\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A <code class=\"docutils literal notranslate\"><span class=\"pre\">QuerySet</span></code> that represents the objects. If provided, the value of\n<code class=\"docutils literal notranslate\"><span class=\"pre\">queryset</span></code> supersedes the value provided for <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.model\" title=\"django.views.generic.detail.SingleObjectMixin.model\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">model</span></code></a>.</p>\n<aside class=\"admonition admonition-warning\" role=\"note\">\n<p class=\"admonition-title\">Warning</p>\n<p><code class=\"docutils literal notranslate\"><span class=\"pre\">queryset</span></code> is a class attribute with a <em>mutable</em> value so care\nmust be taken when using it directly. Before using it, either call\nits <a class=\"reference internal\" href=\"/en/4.0/ref/models/querysets/#django.db.models.query.QuerySet.all\" title=\"django.db.models.query.QuerySet.all\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">all()</span></code></a> method or\nretrieve it with <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.get_queryset\" title=\"django.views.generic.detail.SingleObjectMixin.get_queryset\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_queryset()</span></code></a> which takes care of the\ncloning behind the scenes.</p>\n</aside>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.slug_field\">\n<span class=\"sig-name descname\"><span class=\"pre\">slug_field</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.slug_field\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name of the field on the model that contains the slug. By default,\n<code class=\"docutils literal notranslate\"><span class=\"pre\">slug_field</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">'slug'</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.slug_url_kwarg\">\n<span class=\"sig-name descname\"><span class=\"pre\">slug_url_kwarg</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.slug_url_kwarg\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name of the URLConf keyword argument that contains the slug. By\ndefault, <code class=\"docutils literal notranslate\"><span class=\"pre\">slug_url_kwarg</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">'slug'</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.pk_url_kwarg\">\n<span class=\"sig-name descname\"><span class=\"pre\">pk_url_kwarg</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.pk_url_kwarg\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The name of the URLConf keyword argument that contains the primary key.\nBy default, <code class=\"docutils literal notranslate\"><span class=\"pre\">pk_url_kwarg</span></code> is <code class=\"docutils literal notranslate\"><span class=\"pre\">'pk'</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.context_object_name\">\n<span class=\"sig-name descname\"><span class=\"pre\">context_object_name</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.context_object_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Designates the name of the variable to use in the context.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.query_pk_and_slug\">\n<span class=\"sig-name descname\"><span class=\"pre\">query_pk_and_slug</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.query_pk_and_slug\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>If <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, causes <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.get_object\" title=\"django.views.generic.detail.SingleObjectMixin.get_object\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_object()</span></code></a> to perform its lookup using\nboth the primary key and the slug. Defaults to <code class=\"docutils literal notranslate\"><span class=\"pre\">False</span></code>.</p>\n<p>This attribute can help mitigate <a class=\"reference external\" href=\"https://wiki.owasp.org/index.php/Top_10_2013-A4-Insecure_Direct_Object_References\">insecure direct object reference</a>\nattacks. When applications allow access to individual objects by a\nsequential primary key, an attacker could brute-force guess all URLs;\nthereby obtaining a list of all objects in the application. If users\nwith access to individual objects should be prevented from obtaining\nthis list, setting <code class=\"docutils literal notranslate\"><span class=\"pre\">query_pk_and_slug</span></code> to <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code> will help prevent\nthe guessing of URLs as each URL will require two correct,\nnon-sequential arguments. Using a unique slug may serve the same\npurpose, but this scheme allows you to have non-unique slugs.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.get_object\">\n<span class=\"sig-name descname\"><span class=\"pre\">get_object</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">queryset</span></span><span class=\"o\"><span class=\"pre\">=</span></span><span class=\"default_value\"><span class=\"pre\">None</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.get_object\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the single object that this view will display. If <code class=\"docutils literal notranslate\"><span class=\"pre\">queryset</span></code>\nis provided, that queryset will be used as the source of objects;\notherwise, <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.get_queryset\" title=\"django.views.generic.detail.SingleObjectMixin.get_queryset\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_queryset()</span></code></a> will be used. <code class=\"docutils literal notranslate\"><span class=\"pre\">get_object()</span></code> looks\nfor a <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.pk_url_kwarg\" title=\"django.views.generic.detail.SingleObjectMixin.pk_url_kwarg\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">pk_url_kwarg</span></code></a> argument in the arguments to the view; if\nthis argument is found, this method performs a primary-key based lookup\nusing that value. If this argument is not found, it looks for a\n<a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.slug_url_kwarg\" title=\"django.views.generic.detail.SingleObjectMixin.slug_url_kwarg\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">slug_url_kwarg</span></code></a> argument, and performs a slug lookup using the\n<a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.slug_field\" title=\"django.views.generic.detail.SingleObjectMixin.slug_field\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">slug_field</span></code></a>.</p>\n<p>When <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.query_pk_and_slug\" title=\"django.views.generic.detail.SingleObjectMixin.query_pk_and_slug\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">query_pk_and_slug</span></code></a> is <code class=\"docutils literal notranslate\"><span class=\"pre\">True</span></code>, <code class=\"docutils literal notranslate\"><span class=\"pre\">get_object()</span></code> will\nperform its lookup using both the primary key and the slug.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.get_queryset\">\n<span class=\"sig-name descname\"><span class=\"pre\">get_queryset</span></span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.get_queryset\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the queryset that will be used to retrieve the object that\nthis view will display. By default, <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.get_queryset\" title=\"django.views.generic.detail.SingleObjectMixin.get_queryset\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_queryset()</span></code></a> returns the\nvalue of the <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.queryset\" title=\"django.views.generic.detail.SingleObjectMixin.queryset\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">queryset</span></code></a> attribute if it is set, otherwise\nit constructs a <a class=\"reference internal\" href=\"/en/4.0/ref/models/querysets/#django.db.models.query.QuerySet\" title=\"django.db.models.query.QuerySet\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">QuerySet</span></code></a> by calling\nthe <code class=\"docutils literal notranslate\"><span class=\"pre\">all()</span></code> method on the <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.model\" title=\"django.views.generic.detail.SingleObjectMixin.model\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">model</span></code></a> attribute’s default manager.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.get_context_object_name\">\n<span class=\"sig-name descname\"><span class=\"pre\">get_context_object_name</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"n\"><span class=\"pre\">obj</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.get_context_object_name\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Return the context variable name that will be used to contain the\ndata that this view is manipulating. If <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.context_object_name\" title=\"django.views.generic.detail.SingleObjectMixin.context_object_name\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">context_object_name</span></code></a> is\nnot set, the context name will be constructed from the <code class=\"docutils literal notranslate\"><span class=\"pre\">model_name</span></code>\nof the model that the queryset is composed from. For example, the model\n<code class=\"docutils literal notranslate\"><span class=\"pre\">Article</span></code> would have context object named <code class=\"docutils literal notranslate\"><span class=\"pre\">'article'</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.get_context_data\">\n<span class=\"sig-name descname\"><span class=\"pre\">get_context_data</span></span><span class=\"sig-paren\">(</span><em class=\"sig-param\"><span class=\"o\"><span class=\"pre\">**</span></span><span class=\"n\"><span class=\"pre\">kwargs</span></span></em><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.get_context_data\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns context data for displaying the object.</p>\n<p>The base implementation of this method requires that the <code class=\"docutils literal notranslate\"><span class=\"pre\">self.object</span></code>\nattribute be set by the view (even if <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>). Be sure to do this if\nyou are using this mixin without one of the built-in views that does so.</p>\n<p>It returns a dictionary with these contents:</p>\n<ul class=\"simple\">\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">object</span></code>: The object that this view is displaying\n(<code class=\"docutils literal notranslate\"><span class=\"pre\">self.object</span></code>).</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">context_object_name</span></code>: <code class=\"docutils literal notranslate\"><span class=\"pre\">self.object</span></code> will also be stored under\nthe name returned by <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.get_context_object_name\" title=\"django.views.generic.detail.SingleObjectMixin.get_context_object_name\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_context_object_name()</span></code></a>, which defaults\nto the lowercased version of the model name.</p></li>\n</ul>\n<aside class=\"admonition-context-variables-override-values-from-template-context-processors admonition\">\n<p class=\"admonition-title\">Context variables override values from template context processors</p>\n<p>Any variables from <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.get_context_data\" title=\"django.views.generic.detail.SingleObjectMixin.get_context_data\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_context_data()</span></code></a> take precedence over\ncontext variables from <a class=\"reference internal\" href=\"/en/4.0/ref/templates/api/#subclassing-context-requestcontext\"><span class=\"std std-ref\">context processors</span></a>. For example, if your view\nsets the <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.model\" title=\"django.views.generic.detail.SingleObjectMixin.model\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">model</span></code></a> attribute to\n<a class=\"reference internal\" href=\"/en/4.0/ref/contrib/auth/#django.contrib.auth.models.User\" title=\"django.contrib.auth.models.User\"><code class=\"xref py py-class docutils literal notranslate\"><span class=\"pre\">User</span></code></a>, the default context\nobject name of <code class=\"docutils literal notranslate\"><span class=\"pre\">user</span></code> would override the <code class=\"docutils literal notranslate\"><span class=\"pre\">user</span></code> variable from\nthe <a class=\"reference internal\" href=\"/en/4.0/ref/templates/api/#django.contrib.auth.context_processors.auth\" title=\"django.contrib.auth.context_processors.auth\"><code class=\"xref py py-func docutils literal notranslate\"><span class=\"pre\">django.contrib.auth.context_processors.auth()</span></code></a> context\nprocessor. Use <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.get_context_object_name\" title=\"django.views.generic.detail.SingleObjectMixin.get_context_object_name\"><code class=\"xref py py-meth docutils literal notranslate\"><span class=\"pre\">get_context_object_name()</span></code></a> to avoid a clash.</p>\n</aside>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectMixin.get_slug_field\">\n<span class=\"sig-name descname\"><span class=\"pre\">get_slug_field</span></span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectMixin.get_slug_field\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns the name of a slug field to be used to look up by slug. By\ndefault this returns the value of <a class=\"reference internal\" href=\"#django.views.generic.detail.SingleObjectMixin.slug_field\" title=\"django.views.generic.detail.SingleObjectMixin.slug_field\"><code class=\"xref py py-attr docutils literal notranslate\"><span class=\"pre\">slug_field</span></code></a>.</p>\n</dd></dl>\n\n</dd></dl>\n\n</section>\n<section id=\"singleobjecttemplateresponsemixin\">\n<h2><code class=\"docutils literal notranslate\"><span class=\"pre\">SingleObjectTemplateResponseMixin</span></code><a class=\"heading-anchor\" href=\"#singleobjecttemplateresponsemixin\"><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.detail.SingleObjectTemplateResponseMixin\">\n<em class=\"property\"><span class=\"k\"><span class=\"pre\">class</span></span><span class=\"w\"> </span></em><span class=\"sig-prename descclassname\"><span class=\"pre\">django.views.generic.detail.</span></span><span class=\"sig-name descname\"><span class=\"pre\">SingleObjectTemplateResponseMixin</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectTemplateResponseMixin\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>A mixin class that performs template-based response rendering for views\nthat operate upon a single object instance. Requires that the view it is\nmixed with provides <code class=\"docutils literal notranslate\"><span class=\"pre\">self.object</span></code>, the object instance that the view is\noperating on. <code class=\"docutils literal notranslate\"><span class=\"pre\">self.object</span></code> will usually be, but is not required to be,\nan instance of a Django model. It may be <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code> if the view is in the\nprocess of constructing a new instance.</p>\n<p><strong>Extends</strong></p>\n<ul class=\"simple\">\n<li><p><a class=\"reference internal\" href=\"/en/4.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\"><span class=\"pre\">TemplateResponseMixin</span></code></a></p></li>\n</ul>\n<p><strong>Methods and Attributes</strong></p>\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectTemplateResponseMixin.template_name_field\">\n<span class=\"sig-name descname\"><span class=\"pre\">template_name_field</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectTemplateResponseMixin.template_name_field\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The field on the current object instance that can be used to determine\nthe name of a candidate template. If either <code class=\"docutils literal notranslate\"><span class=\"pre\">template_name_field</span></code>\nitself or the value of the <code class=\"docutils literal notranslate\"><span class=\"pre\">template_name_field</span></code> on the current\nobject instance is <code class=\"docutils literal notranslate\"><span class=\"pre\">None</span></code>, the object will not be used for a\ncandidate template name.</p>\n</dd></dl>\n\n<dl class=\"py attribute\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectTemplateResponseMixin.template_name_suffix\">\n<span class=\"sig-name descname\"><span class=\"pre\">template_name_suffix</span></span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectTemplateResponseMixin.template_name_suffix\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>The suffix to append to the auto-generated candidate template name.\nDefault suffix is <code class=\"docutils literal notranslate\"><span class=\"pre\">_detail</span></code>.</p>\n</dd></dl>\n\n<dl class=\"py method\">\n<dt class=\"sig sig-object py\" id=\"django.views.generic.detail.SingleObjectTemplateResponseMixin.get_template_names\">\n<span class=\"sig-name descname\"><span class=\"pre\">get_template_names</span></span><span class=\"sig-paren\">(</span><span class=\"sig-paren\">)</span><a class=\"heading-anchor\" href=\"#django.views.generic.detail.SingleObjectTemplateResponseMixin.get_template_names\"><span class=\"visually-hidden\">Link to this definition</span><span aria-hidden=\"true\">#</span></a></dt>\n<dd><p>Returns a list of candidate template names. Returns the following list:</p>\n<ul class=\"simple\">\n<li><p>the value of <code class=\"docutils literal notranslate\"><span class=\"pre\">template_name</span></code> on the view (if provided)</p></li>\n<li><p>the contents of the <code class=\"docutils literal notranslate\"><span class=\"pre\">template_name_field</span></code> field on the\nobject instance that the view is operating upon (if available)</p></li>\n<li><p><code class=\"docutils literal notranslate\"><span class=\"pre\">&lt;app_label&gt;/&lt;model_name&gt;&lt;template_name_suffix&gt;.html</span></code></p></li>\n</ul>\n</dd></dl>\n\n</dd></dl>\n\n</section>","rootId":"single-object-mixins","toc":[{"title":"SingleObjectMixin","anchor":"singleobjectmixin","children":[]},{"title":"SingleObjectTemplateResponseMixin","anchor":"singleobjecttemplateresponsemixin","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/en/4.0/ref/"},{"docname":"ref/class-based-views/index","title":"Built-in class-based views API","url":"/en/4.0/ref/class-based-views/"},{"docname":"ref/class-based-views/mixins","title":"Class-based views mixins","url":"/en/4.0/ref/class-based-views/mixins/"}],"prev":{"docname":"ref/class-based-views/mixins-simple","title":"Simple mixins","url":"/en/4.0/ref/class-based-views/mixins-simple/"},"next":{"docname":"ref/class-based-views/mixins-multiple-object","title":"Multiple object mixins","url":"/en/4.0/ref/class-based-views/mixins-multiple-object/"},"formats":{"html":"/en/4.0/ref/class-based-views/mixins-single-object/","markdown":"/en/4.0/ref/class-based-views/mixins-single-object.md","json":"/en/4.0/ref/class-based-views/mixins-single-object.json"},"source":"https://github.com/django/django/blob/stable/4.0.x/docs/ref/class-based-views/mixins-single-object.txt","official":"https://docs.djangoproject.com/en/4.0/ref/class-based-views/mixins-single-object/","inVersions":["dev","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","1.8"],"inLocales":["en","zh-hans","fr","ja","id","it","pt-br","ko","es","el","pl"]}