A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.djangoproject.com/en/stable/internals/contributing/writing-documentation/ below:

Writing documentation | Django documentation

Writing documentation

We place high importance on the 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.

Documentation changes generally come in two forms:

This section explains how writers can craft their documentation changes in the most useful and least error-prone ways.

The Django documentation process

Though Django’s documentation is intended to be read as HTML at https://docs.djangoproject.com/, we edit it as a collection of plain text files written in the reStructuredText markup language for maximum flexibility.

We work from the development version of the repository because it has the latest-and-greatest documentation, just as it has the latest-and-greatest code.

We also backport documentation fixes and improvements, at the discretion of the merger, to the last release branch. This is because it’s advantageous to have the docs for the last release be up-to-date and correct (see Differences between versions).

Django’s documentation uses the Sphinx documentation system, which in turn is based on docutils. The basic idea is that lightly-formatted plain-text documentation is transformed into HTML, PDF, and any other output format.

Sphinx includes a sphinx-build command for turning reStructuredText into other formats, e.g., HTML and PDF. This command is configurable, but the Django documentation includes a Makefile that provides a shorter make html command.

How the documentation is organized

The documentation is organized into several categories:

How to start contributing documentation Clone the Django repository to your local machine

If you’d like to start contributing to our docs, get the development version of Django from the source code repository (see Installing the development version):

/ 
$ git clone https://github.com/django/django.git
...\> git clone https://github.com/django/django.git

If you’re planning to submit these changes, you might find it useful to make a fork of the Django repository and clone this fork instead.

Set up a virtual environment and install dependencies

Create and activate a virtual environment, then install the dependencies:

$ python -m venv .venv
$ source .venv/bin/activate
$ python -m pip install -r docs/requirements.txt
Build the documentation locally

We can build HTML output from the docs directory:

/ 
...\> cd docs
...\> make.bat html

Your locally-built documentation will be accessible at _build/html/index.html and it can be viewed in any web browser, though it will be themed differently than the documentation at docs.djangoproject.com. This is OK! If your changes look good on your local machine, they’ll look good on the website.

Making edits to the documentation

The source files are .txt files located in the docs/ directory.

These files are written in the reStructuredText markup language. To learn the markup, see the reStructuredText reference.

To edit this page, for example, we would edit the file docs/internals/contributing/writing-documentation.txt and rebuild the HTML with make html.

Spelling check

Before you commit your docs, it’s a good idea to run the spelling checker. You’ll need to install sphinxcontrib-spelling first. Then from the docs directory, run:

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:

Link check

Links in documentation can become broken or changed such that they are no longer the canonical link. Sphinx provides a builder that can check whether the links in the documentation are working. From the docs directory, run:

Output is printed to the terminal, but can also be found in _build/linkcheck/output.txt and _build/linkcheck/output.json.

Warning

The execution of the command requires an internet connection and takes several minutes to complete, because the command tests all the links that are found in the documentation.

Entries that have a status of “working” are fine, those that are “unchecked” or “ignored” have been skipped because they either cannot be checked or have matched ignore rules in the configuration.

Entries that have a status of “broken” need to be fixed. Those that have a status of “redirected” may need to be updated to point to the canonical location, e.g. the scheme has changed http://https://. In certain cases, we do not want to update a “redirected” link, e.g. a rewrite to always point to the latest or stable version of the documentation, e.g. /en/stable//en/3.2/.

Writing style

When using pronouns in reference to a hypothetical person, such as “a user with a session cookie”, gender-neutral pronouns (they/their/them) should be used. Instead of:

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.

Commonly used terms

Here are some style guidelines on commonly used terms throughout the documentation:

Django-specific terminology Guidelines for reStructuredText files

These guidelines regulate the format of our reST (reStructuredText) documentation:

Django-specific markup

Besides Sphinx’s built-in markup, Django’s docs define some extra description units:

Django’s documentation uses a custom console directive for documenting command-line examples involving django-admin, 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:

The example above will render a code example block with two tabs. The first one will show:

(No changes from what .. code-block:: console would have rendered).

The second one will show:

Documenting new features

Our policy for new features is:

All documentation of new features should be written in a way that clearly designates the features that 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 remove the .. versionadded:: A.B annotation without any indentation changes when the time comes.

Minimizing images

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"`
...\> 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.

An example

For a quick example of how it all fits together, consider this hypothetical example:

That’s basically how everything fits together.

Translating documentation

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, in the docs directory, run:

The new man page will be written in docs/_build/man/django-admin.1.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4