티스토리 수익 글 보기
The Django admin documentation generator¶
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 that documentation available from the
Django admin.
개요¶
To activate the admindocs, you will need to do
the following:
- Add
django.contrib.admindocsto yourINSTALLED_APPS. - Add
path('admin/doc/', include('django.contrib.admindocs.urls'))to yoururlpatterns. 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 (https://docutils.sourceforge.io/).
- Optional: Using the admindocs bookmarklets requires
django.contrib.admindocs.middleware.XViewMiddlewareto be installed.
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:
| Django Component | reStructuredText roles |
|---|---|
| 모델 | :model:`app_label.ModelName` |
| 뷰 | :view:`app_label.view_name` |
| 템플릿 태그 | :tag:`tagname` |
| 템플릿 필터 | :filter:`filtername` |
| 템플릿 | :template:`path/to/template.html` |
Model reference¶
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.
A model with useful documentation might look like this:
class BlogEntry(models.Model):
"""
Stores a single blog entry, related to :model:`blog.Blog` and
:model:`auth.User`.
"""
slug = models.SlugField(help_text="A short label, generally used in URLs.")
author = models.ForeignKey(
User,
models.SET_NULL,
blank=True,
null=True,
)
blog = models.ForeignKey(Blog, models.CASCADE)
...
def publish(self):
"""Makes the blog entry live on the site."""
...
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.
예시:
from django.shortcuts import render
from myapp.models import MyModel
def my_view(request, slug):
"""
Display an individual :model:`myapp.MyModel`.
**Context**
``mymodel``
An instance of :model:`myapp.MyModel`.
**Template:**
:template:`myapp/my_template.html`
"""
context = {"mymodel": MyModel.objects.get(slug=slug)}
return render(request, "myapp/my_template.html", context)
Template tags and filters reference¶
The tags and filters admindocs sections describe all the tags and
filters that come with Django (in fact, the built-in tag reference and built-in filter reference documentation come directly from those
pages). Any tags or filters that you create or are added by a third-party app
will show up in these sections as well.
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 template loaders. This can be a handy way to
check if the specified template exists and to show where on the filesystem that
template is stored.
Included Bookmarklets¶
One bookmarklet is available from the admindocs page:
- 이 페이지의 문서
- 각 페이지로에서 해당 페이지를 생성한 뷰의 문서로 갑니다.
Using this bookmarklet requires that XViewMiddleware is installed and that
you are logged into the Django admin as a
User with
is_staff set to True.
추가 정보
Support Django!
목차
도움말
- 자주 묻는 질문
- 공통적인 질문에 대한 답을 FAQ에서 찾아보세요.
- 색인, 모듈 색인, or 목차
- 특정한 주제에 대한 정보를 찾는데 유용합니다.
- Django Discord Server
- Join the Django Discord Community.
- Official Django Forum
- Join the community on the Django Forum.
- Ticket tracker
- 티켓 트래커를 통해 Django 혹은 Django 문서의 버그를 신고해주세요.
다운로드:
오프라인(Django 4.2):
HTML |
PDF |
ePub
Read the Docs 제공.