우리는 문서의 일관성과 가독성을 매우 중요하게 여깁니다. Django는 저널리즘 환경에서 창조된 것이니까요! 우리는 문서를 코드처럼 다루며, 될 수 있는 한 자주 개선하는 것을 목표로 합니다.
문서 변경은 다음 두 가지 형태로 이뤄집니다.
이 절에서는 저자들이 어떻게 유용하고도 오류를 적게 일으키는 방식으로 문서 변경을 다루는지 설명합니다.
Django 문서는 https://docs.djangoproject.com/에서 HTML로 읽도록 되어 있지만, 유연성을 위해 텍스트 파일의 묶음으로서 편집합니다. 이 파일들은 Django 릴리스의 최상위 docs/
디렉터리에 있습니다.
문서 작성에 참여하고 싶다면 소스 코드 저장소에서 Django 개발 버전을 받으세요(Installing the development version 참조). 개발 버전에는 최신 코드와 함께 최신 문서가 있습니다. 문서 수정과 개선은 커미터의 재량에 따라 최종 릴리스 브랜치에 백포트합니다. 최종 릴리스에 대한 문서가 최신의 올바른 내용을 담고 있는 것은 매우 유용하기 때문입니다(버전 간 차이점 참조).
Django 문서는 docutils를 기반으로 하는 Sphinx 문서화 시스템을 사용합니다. Sphinx는 가벼운 형식의 일반 텍스트 문서를 HTML, PDF, 기타 여러 형식으로 변환해줍니다.
로컬에서 문서를 빌드하려면 Sphinx를 설치하세요.
$ pip install Sphinx
...\> pip install Sphinx
docs
디렉터리에서 HTML을 빌드합니다.
$ make html
...\> make.bat html
문서 작성에 참여하려면 reStructuredText reference를 읽어보세요.
로컬에 구축한 문서화 시스템에서는 docs.djangoproject.com와 다른 테마가 적용됩니다. 이것은 괜찮습니다! 변경 사항이 로컬 머신에서 문제를 일으키지 않는다면 웹사이트에서도 제대로 보일 것입니다.
문서는 여러 범주로 나뉩니다.
튜토리얼은 독자로 하여금 차근차근 따라 하면서 뭔가 만들어 볼 수 있도록 해줍니다.
튜토리얼에서 가장 중요한 것은 독자가 최대한 빠르게 유용한 것을 만들어 봄으로써 자신감을 갖도록 하는 것입니다.
우리가 해결하고자 하는 문제의 성질을 설명하여, 우리가 무엇을 이루려고 하는지 독자에게 이해시킵니다. 동작 원리를 설명하려고 애쓰지 않아도 됩니다. 무엇을 설명하는지보다 독자가 무엇을 하는지가 더 중요합니다. 무엇을 했는지 나중에 되짚어보면서 설명하는 것이 도움이 될 것입니다.
주제 가이드는 개념 또는 주제를 고수준에서 설명하는 것을 목적으로 합니다.
참고 자료에 있는 내용을 반복하지 말고 링크를 거세요. 예제를 사용하고, 매우 기초적인 내용에 대한 설명을 아끼지 마세요. 그런 설명을 필요로 하는 사람이 있을 지 모릅니다.
해당 주제를 처음 접하는 사람들을 위해 배경 지식을 설명하는 것은 그들이 이미 알고 있는 것과 연결하는 데 도움이 됩니다.
참조 가이드는 API에 대한 기술적 참조를 포함합니다. 그것들은 Django의 내부 동작 원리를 기술하고 사용법을 가르칩니다.
참고 자료는 주제에 집중해야 합니다. 독자가 이미 기본 개념을 알고 있되 Django에서 그것을 어떻게 다루는지에 대한 설명이 필요할 것으로 가정하세요.
참조 가이드는 일반적인 설명을 위한 것이 아닙니다. 기본 개념에 대해 설명하고 있다고 느껴지면, 그것을 주제 가이드로 옮기기 바랍니다.
How-to 가이드는 주요한 주제에 있어서 독자가 따라할 수 있는 레시피입니다.
how-to 가이드에서는 사용자가 달성하고자 하는 것이 중요합니다. how-to에서는 Django의 내부 구현에 대한 세부 사항보다는 결과물을 도출하는 데 집중해야 합니다.
how-to 가이드는 튜토리얼보다 수준이 높으며, 독자가 Django의 동작 원리에 대한 지식이 있을 것으로 간주합니다. 독자가 이미 튜토리얼을 읽은 것으로 간주하고, 같은 내용을 반복하지 말고 관련 튜토리얼에 대한 참조를 제공하세요.
가상의 인물을 가리킬 때는 "세션 쿠키를 가진 사용자"와 같이 중성적인 대명사(they/their/them)을 사용해야 합니다. 예:
Try to avoid using words that minimize the difficulty involved in a task or operation, such as "easily", "simply", "just", "merely", "straightforward", and so on. People's experience may not match your expectations, and they may become frustrated when they do not find a step as "straightforward" or "simple" as it is implied to be.
다음은 문서에서 공통적으로 사용되는 용어에 대한 지침입니다.
These guidelines regulate the format of our reST (reStructuredText) documentation:
In section titles, capitalize only initial words and proper nouns.
Wrap the documentation at 80 characters wide, unless a code example is significantly less readable when split over two lines, or for another good reason.
The main thing to keep in mind as you write and edit docs is that the more semantic markup you can add the better. So:
Add ``django.contrib.auth`` to your ``INSTALLED_APPS``...
Isn't nearly as helpful as:
Add :mod:`django.contrib.auth` to your :setting:`INSTALLED_APPS`...
This is because Sphinx will generate proper links for the latter, which greatly helps readers.
You can prefix the target with a ~
(that's a tilde) to get just the
"last bit" of that path. So :mod:`~django.contrib.auth`
will just
display a link with the title "auth".
Use intersphinx
to reference Python's and Sphinx'
documentation.
Add .. code-block:: <lang>
to literal blocks so that they get
highlighted. Prefer relying on automatic highlighting simply using ::
(two colons). This has the benefit that if the code contains some invalid
syntax, it won't be highlighted. Adding .. code-block:: python
, for
example, will force highlighting despite invalid syntax.
Use these heading styles:
===
One
===
Two
===
Three
-----
Four
~~~~
Five
^^^^
Use :rfc:
to reference RFC and and try to link to the
relevant section if possible. For example, use :rfc:`2324#section-2.3.2`
or :rfc:`Custom link text <2324#section-2.3.2>`
.
Besides Sphinx's built-in markup, Django's docs define some extra description units:
Settings:
.. setting:: INSTALLED_APPS
To link to a setting, use :setting:`INSTALLED_APPS`
.
Template tags:
.. templatetag:: regroup
To link, use :ttag:`regroup`
.
Template filters:
.. templatefilter:: linebreaksbr
To link, use :tfilter:`linebreaksbr`
.
Field lookups (i.e. Foo.objects.filter(bar__exact=whatever)
):
.. fieldlookup:: exact
To link, use :lookup:`exact`
.
django-admin
commands:
.. django-admin:: migrate
To link, use :djadmin:`migrate`
.
django-admin
command-line options:
.. django-admin-option:: --traceback
To link, use :option:`command_name --traceback`
(or omit command_name
for the options shared by all commands like --verbosity
).
Links to Trac tickets (typically reserved for patch release notes):
:ticket:`12345`
Django's documentation uses a custom console
directive for documenting
command-line examples involving django-admin.py
, manage.py
, python
,
etc.). In the HTML documentation, it renders a two-tab UI, with one tab showing
a Unix-style command prompt and a second tab showing a Windows prompt.
For example, you can replace this fragment:
use this command:
.. code-block:: console
$ python manage.py shell
with this one:
use this command:
.. console::
$ python manage.py shell
Notice two things:
.. code-block:: console
directive.'$'
prompt symbol,
'/'
as filesystem path components separator, etc.)The example above will render a code example block with two tabs. The first one will show:
$ python manage.py shell
(No changes from what .. code-block:: console
would have rendered).
The second one will show:
...\> py manage.py shell
Our policy for new features is:
All documentation of new features should be written in a way that clearly designates the features are only available in the Django development version. Assume documentation readers are using the latest release, not the development version.
Our preferred way for marking new features is by prefacing the features'
documentation with: ".. versionadded:: X.Y
", followed by a mandatory
blank line and an optional description (indented).
General improvements, or other changes to the APIs that should be emphasized
should use the ".. versionchanged:: X.Y
" directive (with the same format
as the versionadded
mentioned above.
These versionadded
and versionchanged
blocks should be "self-contained."
In other words, since we only keep these annotations around for two releases,
it's nice to be able to remove the annotation and its contents without having
to reflow, reindent, or edit the surrounding text. For example, instead of
putting the entire description of a new or changed feature in a block, do
something like this:
.. class:: Author(first_name, last_name, middle_name=None)
A person who writes books.
``first_name`` is ...
...
``middle_name`` is ...
.. versionchanged:: A.B
The ``middle_name`` argument was added.
Put the changed annotation notes at the bottom of a section, not the top.
Also, avoid referring to a specific version of Django outside a
versionadded
or versionchanged
block. Even inside a block, it's often
redundant to do so as these annotations render as "New in Django A.B:" and
"Changed in Django A.B", respectively.
If a function, attribute, etc. is added, it's also okay to use a
versionadded
annotation like this:
.. attribute:: Author.middle_name
.. versionadded:: A.B
An author's middle name.
We can simply remove the .. versionadded:: A.B
annotation without any
indentation changes when the time comes.
Optimize image compression where possible. For PNG files, use OptiPNG and
AdvanceCOMP's advpng
:
$ cd docs
$ optipng -o7 -zm1-9 -i0 -strip all `find . -type f -not -path "./_build/*" -name "*.png"`
$ advpng -z4 `find . -type f -not -path "./_build/*" -name "*.png"`
This is based on OptiPNG version 0.7.5. Older versions may complain about the
--strip all
option being lossy.
For a quick example of how it all fits together, consider this hypothetical example:
First, the ref/settings.txt
document could have an overall layout
like this:
========
Settings
========
...
.. _available-settings:
Available settings
==================
...
.. _deprecated-settings:
Deprecated settings
===================
...
Next, the topics/settings.txt
document could contain something like
this:
You can access a :ref:`listing of all available settings
<available-settings>`. For a list of deprecated settings see
:ref:`deprecated-settings`.
You can find both in the :doc:`settings reference document
</ref/settings>`.
We use the Sphinx doc
cross reference element when we want to
link to another document as a whole and the ref
element when
we want to link to an arbitrary location in a document.
Next, notice how the settings are annotated:
.. setting:: ADMINS
ADMINS
======
Default: ``[]`` (Empty list)
A list of all the people who get code error notifications. When
``DEBUG=False`` and a view raises an exception, Django will email these people
with the full exception information. Each member of the list should be a tuple
of (Full name, email address). Example::
[('John', 'john@example.com'), ('Mary', 'mary@example.com')]
Note that Django will email *all* of these people whenever an error happens.
See :doc:`/howto/error-reporting` for more information.
This marks up the following header as the "canonical" target for the
setting ADMINS
. This means any time I talk about ADMINS
,
I can reference it using :setting:`ADMINS`
.
That's basically how everything fits together.
Before you commit your docs, it's a good idea to run the spelling checker. You'll need to install a couple packages first:
Then from the docs
directory, run make spelling
. Wrong words (if any)
along with the file and line number where they occur will be saved to
_build/spelling/output.txt
.
If you encounter false-positives (error output that actually is correct), do one of the following:
docs/spelling_wordlist
(please keep the list in alphabetical order).See Localizing the Django documentation if you'd like to help translate the documentation into another language.
django-admin
man page¶Sphinx can generate a manual page for the
django-admin command. This is configured in
docs/conf.py
. Unlike other documentation output, this man page should be
included in the Django repository and the releases as
docs/man/django-admin.1
. There isn't a need to update this file when
updating the documentation, as it's updated once as part of the release process.
To generate an updated version of the man page, run make man
in the
docs
directory. The new man page will be written in
docs/_build/man/django-admin.1
.
12월 02, 2019