documentation.txt 6.1 KB

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