The Django admin documentation generator
To activate the admindocs, you will need to do the following:
- Add to your INSTALLED_APPS.
- Add to your
urlpatterns
. Make sure it’s included before the'admin/'
entry, so that requests to/admin/doc/
don’t get handled by the latter entry. - Install the docutils Python module ().
Once those steps are complete, you can start browsing the documentation by going to your admin interface and clicking the “Documentation” link in the upper right of the page.
Documentation helpers
The following special markup can be used in your docstrings to easily create hyperlinks to other components:
The models section of the admindocs
page describes each model in the system along with all the fields, properties, and methods available on it. Relationships to other models appear as hyperlinks. Descriptions are pulled from help_text
attributes on fields or from docstrings on model methods.
Older versions don’t display model cached properties.
A model with useful documentation might look like this:
View reference
Each URL in your site has a separate entry in the admindocs
page, and clicking on a given URL will show you the corresponding view. Helpful things you can document in your view function docstrings include:
- A short description of what the view does.
- The context, or a list of variables available in the view’s template.
- The name of the template or templates that are used for that view.
For example:
from django.shortcuts import render
from myapp.models import MyModel
def my_view(request, slug):
"""
Display an individual :model:`myapp.MyModel`.
**Context**
An instance of :model:`myapp.MyModel`.
**Template:**
:template:`myapp/my_template.html`
"""
context = {'mymodel': MyModel.objects.get(slug=slug)}
Template reference
While admindocs
does not include a place to document templates by themselves, if you use the :template:`path/to/template.html`
syntax in a docstring the resulting page will verify the path of that template with Django’s . This can be a handy way to check if the specified template exists and to show where on the filesystem that template is stored.
One bookmarklet is available from the admindocs
page:
Documentation for this page
Jumps you from any page to the documentation for the view that generates that page.