{"title":"The Django admin documentation generator","version":"1.8","locale":"en","docname":"ref/contrib/admin/admindocs","url":"/en/1.8/ref/contrib/admin/admindocs/","canonical":"https://djangodocs.dev/en/1.8/ref/contrib/admin/admindocs/","summary":"Django’s admindocs app pulls documentation from the docstrings of models, views, template tags, and template filters for any app in INSTALLED_APPS and makes…","html":"<span id=\"the-django-admin-documentation-generator\"></span><h1>The Django admin documentation generator<a class=\"heading-anchor\" href=\"#module-django.contrib.admindocs\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>Django’s <a class=\"reference internal\" href=\"#module-django.contrib.admindocs\" title=\"django.contrib.admindocs: Django's admin documentation generator.\"><code class=\"xref py py-mod docutils literal notranslate\">admindocs</code></a> app pulls documentation from the\ndocstrings of models, views, template tags, and template filters for any app in\n<a class=\"reference internal\" href=\"/en/1.8/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\">INSTALLED_APPS</code></a> and makes that documentation available from the\n<a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#module-django.contrib.admin\" title=\"django.contrib.admin: Django's admin site.\"><code class=\"xref py py-mod docutils literal notranslate\">Django admin</code></a>.</p>\n<p>You may, to some extent, utilize <a class=\"reference internal\" href=\"#module-django.contrib.admindocs\" title=\"django.contrib.admindocs: Django's admin documentation generator.\"><code class=\"xref py py-mod docutils literal notranslate\">admindocs</code></a> to quickly\ndocument your own code. This has limited usage, however, as the app is\nprimarily intended for documenting templates, template tags, and filters.\nFor example, model methods that require arguments are purposefully omitted\nfrom the documentation because they can’t be invoked from templates. The app\ncan still be useful since it doesn’t require you to write any extra\ndocumentation (besides docstrings) and is conveniently available from the\n<a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#module-django.contrib.admin\" title=\"django.contrib.admin: Django's admin site.\"><code class=\"xref py py-mod docutils literal notranslate\">Django admin</code></a>.</p>\n<section id=\"overview\">\n<h2>Overview<a class=\"heading-anchor\" href=\"#overview\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>To activate the <a class=\"reference internal\" href=\"#module-django.contrib.admindocs\" title=\"django.contrib.admindocs: Django's admin documentation generator.\"><code class=\"xref py py-mod docutils literal notranslate\">admindocs</code></a>, you will need to do\nthe following:</p>\n<ul class=\"simple\">\n<li><p>Add <a class=\"reference internal\" href=\"#module-django.contrib.admindocs\" title=\"django.contrib.admindocs: Django's admin documentation generator.\"><code class=\"xref py py-mod docutils literal notranslate\">django.contrib.admindocs</code></a> to your <a class=\"reference internal\" href=\"/en/1.8/ref/settings/#std-setting-INSTALLED_APPS\"><code class=\"xref std std-setting docutils literal notranslate\">INSTALLED_APPS</code></a>.</p></li>\n<li><p>Add <code class=\"docutils literal notranslate\">url(r'^admin/doc/', include('django.contrib.admindocs.urls'))</code> to\nyour <code class=\"docutils literal notranslate\">urlpatterns</code>. Make sure it’s included <em>before</em> the\n<code class=\"docutils literal notranslate\">r'^admin/'</code> entry, so that requests to <code class=\"docutils literal notranslate\">/admin/doc/</code> don’t get\nhandled by the latter entry.</p></li>\n<li><p>Install the docutils Python module (<a class=\"reference external\" href=\"http://docutils.sf.net/\">http://docutils.sf.net/</a>).</p></li>\n<li><p><strong>Optional:</strong> Using the admindocs bookmarklets requires\n<code class=\"docutils literal notranslate\">django.contrib.admindocs.middleware.XViewMiddleware</code> to be installed.</p></li>\n</ul>\n<p>Once those steps are complete, you can start browsing the documentation by\ngoing to your admin interface and clicking the “Documentation” link in the\nupper right of the page.</p>\n</section>\n<section id=\"documentation-helpers\">\n<h2>Documentation helpers<a class=\"heading-anchor\" href=\"#documentation-helpers\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The following special markup can be used in your docstrings to easily create\nhyperlinks to other components:</p>\n<div class=\"table-scroll\" role=\"region\" tabindex=\"0\" aria-label=\"Table\"><table class=\"docutils align-default\">\n<thead>\n<tr class=\"row-odd\"><th class=\"head\"><p>Django Component</p></th>\n<th class=\"head\"><p>reStructuredText roles</p></th>\n</tr>\n</thead>\n<tbody>\n<tr class=\"row-even\"><td><p>Models</p></td>\n<td><p><code class=\"docutils literal notranslate\">:model:`app_label.ModelName`</code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p>Views</p></td>\n<td><p><code class=\"docutils literal notranslate\">:view:`app_label.view_name`</code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p>Template tags</p></td>\n<td><p><code class=\"docutils literal notranslate\">:tag:`tagname`</code></p></td>\n</tr>\n<tr class=\"row-odd\"><td><p>Template filters</p></td>\n<td><p><code class=\"docutils literal notranslate\">:filter:`filtername`</code></p></td>\n</tr>\n<tr class=\"row-even\"><td><p>Templates</p></td>\n<td><p><code class=\"docutils literal notranslate\">:template:`path/to/template.html`</code></p></td>\n</tr>\n</tbody>\n</table>\n</div>\n</section>\n<section id=\"model-reference\">\n<h2>Model reference<a class=\"heading-anchor\" href=\"#model-reference\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The <strong>models</strong> section of the <code class=\"docutils literal notranslate\">admindocs</code> page describes each model in the\nsystem along with all the fields and methods (without any arguments) available\non it. While model properties don’t have any arguments, they are not listed.\nRelationships to other models appear as hyperlinks. Descriptions are pulled\nfrom <code class=\"docutils literal notranslate\">help_text</code> attributes on fields or from docstrings on model methods.</p>\n<p>A model with useful documentation might look like this:</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=\"k\">class</span> <span class=\"nc\">BlogEntry</span><span class=\"p\">(</span>models<span class=\"o\">.</span>Model<span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    Stores a single blog entry, related to :model:`blog.Blog` and</span>\n<span class=\"sd\">    :model:`auth.User`.</span>\n\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n    slug <span class=\"o\">=</span> models<span class=\"o\">.</span>SlugField<span class=\"p\">(</span>help_text<span class=\"o\">=</span><span class=\"s2\">&quot;A short label, generally used in URLs.&quot;</span><span class=\"p\">)</span>\n    author <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>User<span class=\"p\">)</span>\n    blog <span class=\"o\">=</span> models<span class=\"o\">.</span>ForeignKey<span class=\"p\">(</span>Blog<span class=\"p\">)</span>\n    <span class=\"o\">...</span>\n\n    <span class=\"k\">def</span> <span class=\"nf\">publish</span><span class=\"p\">(</span><span class=\"bp\">self</span><span class=\"p\">):</span>\n        <span class=\"sd\">&quot;&quot;&quot;Makes the blog entry live on the site.&quot;&quot;&quot;</span>\n        <span class=\"o\">...</span>\n</code></pre></div>\n</section>\n<section id=\"view-reference\">\n<h2>View reference<a class=\"heading-anchor\" href=\"#view-reference\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Each URL in your site has a separate entry in the <code class=\"docutils literal notranslate\">admindocs</code> page, and\nclicking on a given URL will show you the corresponding view. Helpful things\nyou can document in your view function docstrings include:</p>\n<ul class=\"simple\">\n<li><p>A short description of what the view does.</p></li>\n<li><p>The <strong>context</strong>, or a list of variables available in the view’s template.</p></li>\n<li><p>The name of the template or templates that are used for that view.</p></li>\n</ul>\n<p>For example:</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> render\n\n<span class=\"kn\">from</span> <span class=\"nn\">myapp.models</span> <span class=\"kn\">import</span> MyModel\n\n<span class=\"k\">def</span> <span class=\"nf\">my_view</span><span class=\"p\">(</span>request<span class=\"p\">,</span> slug<span class=\"p\">):</span>\n    <span class=\"sd\">&quot;&quot;&quot;</span>\n<span class=\"sd\">    Display an individual :model:`myapp.MyModel`.</span>\n\n<span class=\"sd\">    **Context**</span>\n\n<span class=\"sd\">    ``mymodel``</span>\n<span class=\"sd\">        An instance of :model:`myapp.MyModel`.</span>\n\n<span class=\"sd\">    **Template:**</span>\n\n<span class=\"sd\">    :template:`myapp/my_template.html`</span>\n\n<span class=\"sd\">    &quot;&quot;&quot;</span>\n    context <span class=\"o\">=</span> <span class=\"p\">{</span><span class=\"s1\">&#39;mymodel&#39;</span><span class=\"p\">:</span> MyModel<span class=\"o\">.</span>objects<span class=\"o\">.</span>get<span class=\"p\">(</span>slug<span class=\"o\">=</span>slug<span class=\"p\">)}</span>\n    <span class=\"k\">return</span> render<span class=\"p\">(</span>request<span class=\"p\">,</span> <span class=\"s1\">&#39;myapp/my_template.html&#39;</span><span class=\"p\">,</span> context<span class=\"p\">)</span>\n</code></pre></div>\n</section>\n<section id=\"template-tags-and-filters-reference\">\n<h2>Template tags and filters reference<a class=\"heading-anchor\" href=\"#template-tags-and-filters-reference\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>The <strong>tags</strong> and <strong>filters</strong> <code class=\"docutils literal notranslate\">admindocs</code> sections describe all the tags and\nfilters that come with Django (in fact, the <a class=\"reference internal\" href=\"/en/1.8/ref/templates/builtins/#ref-templates-builtins-tags\"><span class=\"std std-ref\">built-in tag reference</span></a> and <a class=\"reference internal\" href=\"/en/1.8/ref/templates/builtins/#ref-templates-builtins-filters\"><span class=\"std std-ref\">built-in filter reference</span></a> documentation come directly from those\npages). Any tags or filters that you create or are added by a third-party app\nwill show up in these sections as well.</p>\n</section>\n<section id=\"template-reference\">\n<h2>Template reference<a class=\"heading-anchor\" href=\"#template-reference\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>While <code class=\"docutils literal notranslate\">admindocs</code> does not include a place to document templates by\nthemselves, if you use the <code class=\"docutils literal notranslate\">:template:`path/to/template.html`</code> syntax in a\ndocstring the resulting page will verify the path of that template with\nDjango’s <a class=\"reference internal\" href=\"/en/1.8/ref/templates/api/#template-loaders\"><span class=\"std std-ref\">template loaders</span></a>. This can be a handy way to\ncheck if the specified template exists and to show where on the filesystem that\ntemplate is stored.</p>\n</section>\n<section id=\"included-bookmarklets\">\n<span id=\"admindocs-bookmarklets\"></span><h2>Included Bookmarklets<a class=\"heading-anchor\" href=\"#included-bookmarklets\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Several useful bookmarklets are available from the <code class=\"docutils literal notranslate\">admindocs</code> page:</p>\n<dl class=\"simple\">\n<dt>Documentation for this page</dt><dd><p>Jumps you from any page to the documentation for the view that generates\nthat page.</p>\n</dd>\n<dt>Show object ID</dt><dd><p>Shows the content-type and unique ID for pages that represent a single\nobject.</p>\n</dd>\n<dt>Edit this object</dt><dd><p>Jumps to the admin page for pages that represent a single object.</p>\n</dd>\n</dl>\n<p>Using these bookmarklets requires that you are either logged into the\n<a class=\"reference internal\" href=\"/en/1.8/ref/contrib/admin/#module-django.contrib.admin\" title=\"django.contrib.admin: Django's admin site.\"><code class=\"xref py py-mod docutils literal notranslate\">Django admin</code></a> as a\n<a class=\"reference internal\" href=\"/en/1.8/ref/contrib/auth/#id0\" title=\"django.contrib.auth.models.User\"><code class=\"xref py py-class docutils literal notranslate\">User</code></a> with\n<a class=\"reference internal\" href=\"/en/1.8/ref/contrib/auth/#django.contrib.auth.models.User.is_staff\" title=\"django.contrib.auth.models.User.is_staff\"><code class=\"xref py py-attr docutils literal notranslate\">is_staff</code></a> set to <code class=\"docutils literal notranslate\">True</code>, or that the\n<code class=\"docutils literal notranslate\">XViewMiddleware</code> is installed and you are accessing the site from an IP\naddress listed in <a class=\"reference internal\" href=\"/en/1.8/ref/settings/#std-setting-INTERNAL_IPS\"><code class=\"xref std std-setting docutils literal notranslate\">INTERNAL_IPS</code></a>.</p>\n</section>","rootId":"module-django.contrib.admindocs","toc":[{"title":"Overview","anchor":"overview","children":[]},{"title":"Documentation helpers","anchor":"documentation-helpers","children":[]},{"title":"Model reference","anchor":"model-reference","children":[]},{"title":"View reference","anchor":"view-reference","children":[]},{"title":"Template tags and filters reference","anchor":"template-tags-and-filters-reference","children":[]},{"title":"Template reference","anchor":"template-reference","children":[]},{"title":"Included Bookmarklets","anchor":"included-bookmarklets","children":[]}],"breadcrumbs":[{"docname":"ref/index","title":"API Reference","url":"/en/1.8/ref/"},{"docname":"ref/contrib/index","title":"contrib packages","url":"/en/1.8/ref/contrib/"},{"docname":"ref/contrib/admin/index","title":"The Django admin site","url":"/en/1.8/ref/contrib/admin/"}],"prev":{"docname":"ref/contrib/admin/actions","title":"Admin actions","url":"/en/1.8/ref/contrib/admin/actions/"},"next":{"docname":"ref/contrib/auth","title":"django.contrib.auth","url":"/en/1.8/ref/contrib/auth/"},"formats":{"html":"/en/1.8/ref/contrib/admin/admindocs/","markdown":"/en/1.8/ref/contrib/admin/admindocs.md","json":"/en/1.8/ref/contrib/admin/admindocs.json"},"source":"https://github.com/django/django/blob/stable/1.8.x/docs/ref/contrib/admin/admindocs.txt","official":"https://docs.djangoproject.com/en/1.8/ref/contrib/admin/admindocs/","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"]}