2011-05-27 18:49:47 +08:00
|
|
|
=====================
|
|
|
|
Writing documentation
|
|
|
|
=====================
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
We place a high importance on consistency and readability of documentation.
|
|
|
|
After all, Django was created in a journalism environment! So we treat our
|
|
|
|
documentation like we treat our code: we aim to improve it as often as
|
|
|
|
possible.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
Documentation changes generally come in two forms:
|
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* General improvements: typo corrections, error fixes and better
|
|
|
|
explanations through clearer writing and more examples.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* New features: documentation of features that have been added to the
|
|
|
|
framework since the last release.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
|
|
|
This section explains how writers can craft their documentation changes
|
|
|
|
in the most useful and least error-prone ways.
|
|
|
|
|
2012-06-08 00:32:28 +08:00
|
|
|
Getting the raw documentation
|
|
|
|
-----------------------------
|
|
|
|
|
|
|
|
Though Django's documentation is intended to be read as HTML at
|
2012-06-28 16:49:07 +08:00
|
|
|
https://docs.djangoproject.com/, we edit it as a collection of text files for
|
2012-06-08 00:32:28 +08:00
|
|
|
maximum flexibility. These files live in the top-level ``docs/`` directory of a
|
|
|
|
Django release.
|
|
|
|
|
|
|
|
If you'd like to start contributing to our docs, get the development version of
|
|
|
|
Django from the source code repository
|
|
|
|
(see :ref:`installing-development-version`). The development version has the
|
|
|
|
latest-and-greatest documentation, just as it has latest-and-greatest code.
|
2012-10-25 18:51:19 +08:00
|
|
|
We also backport documentation fixes and improvements, at the discretion of the
|
|
|
|
committer, to the last release branch. That's because it's highly advantageous
|
|
|
|
to have the docs for the last release be up-to-date and correct (see
|
2012-06-08 00:32:28 +08:00
|
|
|
:ref:`differences-between-doc-versions`).
|
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
Getting started with Sphinx
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
Django's documentation uses the Sphinx__ documentation system, which in turn
|
|
|
|
is based on docutils__. The basic idea is that lightly-formatted plain-text
|
2008-08-24 06:25:40 +08:00
|
|
|
documentation is transformed into HTML, PDF, and any other output format.
|
|
|
|
|
2013-09-23 01:34:30 +08:00
|
|
|
__ http://sphinx-doc.org/
|
2009-12-26 14:37:26 +08:00
|
|
|
__ http://docutils.sourceforge.net/
|
2008-08-24 06:25:40 +08:00
|
|
|
|
|
|
|
To actually build the documentation locally, you'll currently need to install
|
2012-03-03 17:11:54 +08:00
|
|
|
Sphinx -- ``sudo pip install Sphinx`` should do the trick.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2010-07-26 04:39:40 +08:00
|
|
|
.. note::
|
|
|
|
|
2010-11-20 00:10:23 +08:00
|
|
|
Building the Django documentation requires Sphinx 1.0.2 or newer. Sphinx
|
|
|
|
also requires the Pygments__ library for syntax highlighting; building the
|
|
|
|
Django documentation requires Pygments 1.1 or newer (a new-enough version
|
|
|
|
should automatically be installed along with Sphinx).
|
|
|
|
|
|
|
|
__ http://pygments.org
|
2010-07-26 04:39:40 +08:00
|
|
|
|
2011-07-19 17:00:24 +08:00
|
|
|
Then, building the HTML is easy; just ``make html`` (or ``make.bat html`` on
|
|
|
|
Windows) from the ``docs`` directory.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-09-05 05:17:30 +08:00
|
|
|
To get started contributing, you'll want to read the :ref:`reStructuredText
|
|
|
|
Primer <sphinx:rst-primer>`. After that, you'll want to read about the
|
|
|
|
:ref:`Sphinx-specific markup <sphinx:sphinxmarkup>` that's used to manage
|
|
|
|
metadata, indexing, and cross-references.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
Commonly used terms
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
Here are some style guidelines on commonly used terms throughout the
|
|
|
|
documentation:
|
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **Django** -- when referring to the framework, capitalize Django. It is
|
|
|
|
lowercase only in Python code and in the djangoproject.com logo.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **email** -- no hyphen.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **MySQL**, **PostgreSQL**, **SQLite**
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2013-09-06 06:23:48 +08:00
|
|
|
* **SQL** -- when referring to SQL, the expected pronunciation should be
|
|
|
|
"Ess Queue Ell" and not "sequel". Thus in a phrase like "Returns an
|
|
|
|
SQL expression", "SQL" should be preceded by "an" and not "a".
|
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **Python** -- when referring to the language, capitalize Python.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **realize**, **customize**, **initialize**, etc. -- use the American
|
|
|
|
"ize" suffix, not "ise."
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **subclass** -- it's a single word without a hyphen, both as a verb
|
|
|
|
("subclass that model") and as a noun ("create a subclass").
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **Web**, **World Wide Web**, **the Web** -- note Web is always
|
|
|
|
capitalized when referring to the World Wide Web.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **Web site** -- use two words, with Web capitalized.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
|
|
|
Django-specific terminology
|
|
|
|
---------------------------
|
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **model** -- it's not capitalized.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **template** -- it's not capitalized.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **URLconf** -- use three capitalized letters, with no space before
|
|
|
|
"conf."
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* **view** -- it's not capitalized.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
Guidelines for reStructuredText files
|
|
|
|
-------------------------------------
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
These guidelines regulate the format of our reST (reStructuredText)
|
|
|
|
documentation:
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* In section titles, capitalize only initial words and proper nouns.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* 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.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* 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::
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
Add ``django.contrib.auth`` to your ``INSTALLED_APPS``...
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
Isn't nearly as helpful as::
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
Add :mod:`django.contrib.auth` to your :setting:`INSTALLED_APPS`...
|
2011-05-27 18:49:47 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
This is because Sphinx will generate proper links for the latter, which
|
|
|
|
greatly helps readers. There's basically no limit to the amount of
|
|
|
|
useful markup you can add.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Use :mod:`~sphinx.ext.intersphinx` to reference Python's and Sphinx'
|
|
|
|
documentation.
|
2011-09-05 05:17:30 +08:00
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
Django-specific markup
|
|
|
|
----------------------
|
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
Besides the `Sphinx built-in markup`__, Django's docs defines some extra
|
|
|
|
description units:
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2013-09-23 01:34:30 +08:00
|
|
|
__ http://sphinx-doc.org/markup/desc.html
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Settings::
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. setting:: INSTALLED_APPS
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
To link to a setting, use ``:setting:`INSTALLED_APPS```.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Template tags::
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. templatetag:: regroup
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
To link, use ``:ttag:`regroup```.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Template filters::
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. templatefilter:: linebreaksbr
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
To link, use ``:tfilter:`linebreaksbr```.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Field lookups (i.e. ``Foo.objects.filter(bar__exact=whatever)``)::
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. fieldlookup:: exact
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
To link, use ``:lookup:`exact```.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* ``django-admin`` commands::
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2013-07-25 23:19:36 +08:00
|
|
|
.. django-admin:: migrate
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2013-07-25 23:19:36 +08:00
|
|
|
To link, use ``:djadmin:`migrate```.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* ``django-admin`` command-line options::
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. django-admin-option:: --traceback
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
To link, use ``:djadminopt:`--traceback```.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
.. _documenting-new-features:
|
|
|
|
|
|
|
|
Documenting new features
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
Our policy for new features is:
|
|
|
|
|
2011-07-19 21:16:09 +08:00
|
|
|
All documentation of new features should be written in a way that
|
2011-05-27 18:49:47 +08:00
|
|
|
clearly designates the features are only available in the Django
|
|
|
|
development version. Assume documentation readers are using the latest
|
2011-07-19 21:16:09 +08:00
|
|
|
release, not the development version.
|
2011-05-27 18:49:47 +08:00
|
|
|
|
|
|
|
Our preferred way for marking new features is by prefacing the features'
|
2013-03-25 13:48:23 +08:00
|
|
|
documentation with: "``.. versionadded:: X.Y``", followed by a a mandatory
|
|
|
|
blank line and an optional content (indented).
|
2011-05-27 18:49:47 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
An example
|
|
|
|
----------
|
|
|
|
|
2010-08-20 03:27:44 +08:00
|
|
|
For a quick example of how it all fits together, consider this hypothetical
|
|
|
|
example:
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* First, the ``ref/settings.txt`` document could have an overall layout
|
|
|
|
like this:
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. code-block:: rst
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
========
|
|
|
|
Settings
|
|
|
|
========
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
...
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. _available-settings:
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
Available settings
|
|
|
|
==================
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
...
|
2010-08-20 03:27:44 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. _deprecated-settings:
|
2010-08-20 03:27:44 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
Deprecated settings
|
|
|
|
===================
|
2010-08-20 03:27:44 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
...
|
2010-08-20 03:27:44 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Next, the ``topics/settings.txt`` document could contain something like
|
|
|
|
this:
|
2010-08-20 03:27:44 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. code-block:: rst
|
2010-08-20 03:27:44 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
You can access a :ref:`listing of all available settings
|
|
|
|
<available-settings>`. For a list of deprecated settings see
|
|
|
|
:ref:`deprecated-settings`.
|
2010-08-20 03:27:44 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
You can find both in the :doc:`settings reference document
|
|
|
|
</ref/settings>`.
|
2010-08-20 03:27:44 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
We use the Sphinx :rst:role:`doc` cross reference element when we want to
|
|
|
|
link to another document as a whole and the :rst:role:`ref` element when
|
|
|
|
we want to link to an arbitrary location in a document.
|
2010-08-20 03:27:44 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Next, notice how the settings are annotated:
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. code-block:: rst
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. setting:: ADMIN_FOR
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
ADMIN_FOR
|
|
|
|
---------
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
Default: ``()`` (Empty tuple)
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
Used for admin-site settings modules, this should be a tuple of
|
|
|
|
settings modules (in the format ``'foo.bar.baz'``) for which this site
|
|
|
|
is an admin.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
The admin site uses this in its automatically-introspected
|
|
|
|
documentation of models, views and template tags.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
This marks up the following header as the "canonical" target for the
|
|
|
|
setting ``ADMIN_FOR`` This means any time I talk about ``ADMIN_FOR``,
|
|
|
|
I can reference it using ``:setting:`ADMIN_FOR```.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2008-08-24 06:25:40 +08:00
|
|
|
That's basically how everything fits together.
|
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
.. _improving-the-documentation:
|
|
|
|
|
|
|
|
Improving the documentation
|
|
|
|
---------------------------
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-05-27 18:49:47 +08:00
|
|
|
A few small improvements can be made to make the documentation read and
|
|
|
|
look better:
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Most of the various ``index.txt`` documents have *very* short or even
|
|
|
|
non-existent intro text. Each of those documents needs a good short
|
|
|
|
intro the content below that point.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* The glossary is very perfunctory. It needs to be filled out.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Add more metadata targets. Lots of places look like::
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
``File.close()``
|
|
|
|
~~~~~~~~~~~~~~~~
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
\... these should be::
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
.. method:: File.close()
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
That is, use metadata instead of titles.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Add more links -- nearly everything that's an inline code literal
|
|
|
|
right now can probably be turned into a xref.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
See the ``literals_to_xrefs.py`` file in ``_ext`` -- it's a shell script
|
|
|
|
to help do this work.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
This will probably be a continuing, never-ending project.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Add `info field lists`__ where appropriate.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2013-09-23 01:34:30 +08:00
|
|
|
__ http://sphinx-doc.org/markup/desc.html#info-field-lists
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Whenever possible, use links. So, use ``:setting:`ADMIN_FOR``` instead
|
|
|
|
of ````ADMIN_FOR````.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Use directives where appropriate. Some directives
|
|
|
|
(e.g. ``.. setting::``) are prefix-style directives; they go *before*
|
|
|
|
the unit they're describing. These are known as "crossref" directives.
|
|
|
|
Others (e.g. ``.. class::``) generate their own markup; these should go
|
|
|
|
inside the section they're describing. These are called
|
|
|
|
"description units".
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
You can tell which are which by looking at in
|
|
|
|
:file:`_ext/djangodocs.py`; it registers roles as one of the other.
|
2008-08-24 06:25:40 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* Add ``.. code-block:: <lang>`` to literal blocks so that they get
|
|
|
|
highlighted.
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
* When referring to classes/functions/modules, etc., you'll want to use
|
|
|
|
the fully-qualified name of the target
|
|
|
|
(``:class:`django.contrib.contenttypes.models.ContentType```).
|
2008-09-10 12:04:57 +08:00
|
|
|
|
2011-10-14 08:12:01 +08:00
|
|
|
Since this doesn't look all that awesome in the output -- it shows the
|
|
|
|
entire path to the object -- you can prefix the target with a ``~``
|
|
|
|
(that's a tilde) to get just the "last bit" of that path. So
|
|
|
|
``:class:`~django.contrib.contenttypes.models.ContentType``` will just
|
|
|
|
display a link with the title "ContentType".
|