documentation.txt 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. How the Django documentation works
  2. ==================================
  3. \... and how to contribute.
  4. Django's documentation uses the Sphinx__ documentation system, which in turn is
  5. based on docutils__. The basic idea is that lightly-formatted plain-text
  6. documentation is transformed into HTML, PDF, and any other output format.
  7. __ http://sphinx.pocoo.org/
  8. __ http://docutils.sourceforge.net/
  9. To actually build the documentation locally, you'll currently need to install
  10. Sphinx -- ``easy_install Sphinx`` should do the trick.
  11. .. note::
  12. Generation of the Django documentation will work with Sphinx version 0.6
  13. or newer, but we recommend going straigh to Sphinx 1.0.2 or newer.
  14. Then, building the html is easy; just ``make html`` from the ``docs`` directory.
  15. To get started contributing, you'll want to read the `ReStructuredText
  16. Primer`__. After that, you'll want to read about the `Sphinx-specific markup`__
  17. that's used to manage metadata, indexing, and cross-references.
  18. __ http://sphinx.pocoo.org/rest.html
  19. __ http://sphinx.pocoo.org/markup/
  20. The main thing to keep in mind as you write and edit docs is that the more
  21. semantic markup you can add the better. So::
  22. Add ``django.contrib.auth`` to your ``INSTALLED_APPS``...
  23. Isn't nearly as helpful as::
  24. Add :mod:`django.contrib.auth` to your :setting:`INSTALLED_APPS`...
  25. This is because Sphinx will generate proper links for the latter, which greatly
  26. helps readers. There's basically no limit to the amount of useful markup you can
  27. add.
  28. Django-specific markup
  29. ----------------------
  30. Besides the `Sphinx built-in markup`__, Django's docs defines some extra description units:
  31. __ http://sphinx.pocoo.org/markup/desc.html
  32. * Settings::
  33. .. setting:: INSTALLED_APPS
  34. To link to a setting, use ``:setting:`INSTALLED_APPS```.
  35. * Template tags::
  36. .. templatetag:: regroup
  37. To link, use ``:ttag:`regroup```.
  38. * Template filters::
  39. .. templatefilter:: linebreaksbr
  40. To link, use ``:tfilter:`linebreaksbr```.
  41. * Field lookups (i.e. ``Foo.objects.filter(bar__exact=whatever)``)::
  42. .. fieldlookup:: exact
  43. To link, use ``:lookup:`exact```.
  44. * ``django-admin`` commands::
  45. .. django-admin:: syncdb
  46. To link, use ``:djadmin:`syncdb```.
  47. * ``django-admin`` command-line options::
  48. .. django-admin-option:: --traceback
  49. To link, use ``:djadminopt:`--traceback```.
  50. An example
  51. ----------
  52. For a quick example of how it all fits together, consider this hypothetical
  53. example:
  54. * First, the ``ref/settings.txt`` document could have an overall layout
  55. like this:
  56. .. code-block:: rst
  57. ========
  58. Settings
  59. ========
  60. ...
  61. .. _available-settings:
  62. Available settings
  63. ==================
  64. ...
  65. .. _deprecated-settings:
  66. Deprecated settings
  67. ===================
  68. ...
  69. * Next, the ``topics/settings.txt`` document could contain something like
  70. this:
  71. .. code-block:: rst
  72. You can access a :ref:`listing of all available settings
  73. <available-settings>`. For a list of deprecated settings see
  74. :ref:`deprecated-settings`.
  75. You can find both in the :doc:`settings reference document </ref/settings>`.
  76. We use the Sphinx doc_ cross reference element when we want to link to
  77. another document as a whole and the ref_ element when we want to link to
  78. an arbitrary location in a document.
  79. .. _doc: http://sphinx.pocoo.org/markup/inline.html#role-doc
  80. .. _ref: http://sphinx.pocoo.org/markup/inline.html#role-ref
  81. * Next, notice how the settings are annotated:
  82. .. code-block:: rst
  83. .. setting:: ADMIN_FOR
  84. ADMIN_FOR
  85. ---------
  86. Default: ``()`` (Empty tuple)
  87. Used for admin-site settings modules, this should be a tuple of settings
  88. modules (in the format ``'foo.bar.baz'``) for which this site is an
  89. admin.
  90. The admin site uses this in its automatically-introspected
  91. documentation of models, views and template tags.
  92. This marks up the following header as the "canonical" target for the
  93. setting ``ADMIN_FOR`` This means any time I talk about ``ADMIN_FOR``, I
  94. can reference it using ``:setting:`ADMIN_FOR```.
  95. That's basically how everything fits together.
  96. TODO
  97. ----
  98. The work is mostly done, but here's what's left, in rough order of priority.
  99. * Most of the various ``index.txt`` documents have *very* short or even
  100. non-existent intro text. Each of those documents needs a good short intro
  101. the content below that point.
  102. * The glossary is very perfunctory. It needs to be filled out.
  103. * Add more metadata targets: there's lots of places that look like::
  104. ``File.close()``
  105. ~~~~~~~~~~~~~~~~
  106. \... these should be::
  107. .. method:: File.close()
  108. That is, use metadata instead of titles.
  109. * Add more links -- nearly everything that's an inline code literal
  110. right now can probably be turned into a xref.
  111. See the ``literals_to_xrefs.py`` file in ``_ext`` -- it's a shell script
  112. to help do this work.
  113. This will probably be a continuing, never-ending project.
  114. * Add `info field lists`__ where appropriate.
  115. __ http://sphinx.pocoo.org/markup/desc.html#info-field-lists
  116. * Add ``.. code-block:: <lang>`` to literal blocks so that they get
  117. highlighted.
  118. Hints
  119. -----
  120. Some hints for making things look/read better:
  121. * Whenever possible, use links. So, use ``:setting:`ADMIN_FOR``` instead of
  122. ````ADMIN_FOR````.
  123. * Some directives (``.. setting::``, for one) are prefix-style directives;
  124. they go *before* the unit they're describing. These are known as
  125. "crossref" directives. Others (``.. class::``, e.g.) generate their own
  126. markup; these should go inside the section they're describing. These are
  127. called "description units".
  128. You can tell which are which by looking at in :file:`_ext/djangodocs.py`;
  129. it registers roles as one of the other.
  130. * When referring to classes/functions/modules, etc., you'll want to use the
  131. fully-qualified name of the target
  132. (``:class:`django.contrib.contenttypes.models.ContentType```).
  133. Since this doesn't look all that awesome in the output -- it shows the
  134. entire path to the object -- you can prefix the target with a ``~``
  135. (that's a tilde) to get just the "last bit" of that path. So
  136. ``:class:`~django.contrib.contenttypes.models.ContentType``` will just
  137. display a link with the title "ContentType".