documentation.txt 5.9 KB

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