Skip to main content

django-docutils · Python Package License

docutils (a.k.a. reStructuredText / rst / reST) support for Django.

Documentation: https://django-docutils.git-pull.com/

django-docutils turns off docutils features that are risky on the web — raw HTML pass-through, file inclusion, and local docutils.conf lookup — and filters unsafe link schemes from rendered output. That reduces risk; it does not make untrusted markup safe. If people can submit their own reStructuredText or Markdown to your site (comments, profiles, CMS fields), read the Security topic first.

Quickstart

Install django-docutils:

$ pip install django-docutils

Next, add django_docutils to your INSTALLED_APPS in your settings file:

INSTALLED_APPS = [
    # ... your default apps,
    'django_docutils'
]

Template tag

In your template:

{% load django_docutils %}
{% rst %}
Welcome
=======

Write `reStructuredText <https://docutils.sourceforge.io/rst.html>`_ with
links, **bold** text, and highlighted code:

.. code-block:: python

   print("hello")
{% endrst %}

Template filter

In your template:

{% load django_docutils %}
{% filter rst %}
Welcome
=======

Write `reStructuredText <https://docutils.sourceforge.io/rst.html>`_ with
links, **bold** text, and highlighted code:

.. code-block:: python

   print("hello")
{% endfilter %}

Template engine (class-based view)

You can also use a class-based view to render reStructuredText (reST).

If you want to use reStructuredText as a django template engine, INSTALLED_APPS isn't required, instead you add this to your TEMPLATES variable in your settings:

TEMPLATES = [
    # ... Other engines
    {
        "NAME": "docutils",
        "BACKEND": "django_docutils.template.DocutilsTemplates",
        "DIRS": [],
        "APP_DIRS": True,
    }
]

Now django will be able to scan for .rst files and process them. In your view:

from django_docutils.views import DocutilsView

class HomeView(DocutilsView):
    template_name = 'base.html'
    rst_name = 'home.rst'

Settings

# Optional, automatically maps roles, directives and transformers
DJANGO_DOCUTILS_LIB_RST = {
    "docutils": {
        "strip_comments": True,
        "initial_header_level": 2,
    },
    "roles": {
        "local": {
            "gh": "django_docutils.lib.roles.github.github_role",
            "twitter": "django_docutils.lib.roles.twitter.twitter_role",
            "email": "django_docutils.lib.roles.email.email_role",
        }
    },
    "directives": {
        "code-block": "django_docutils.lib.directives.code.CodeBlock",
    }
}

# Optional
DJANGO_DOCUTILS_LIB_TEXT = {
    "uncapitalized_word_filters": ["project.my_module.my_capitalization_fn"]
}

For trusted static RST only — never for user-submitted content — docutils features that the default rendering disables can be re-enabled with an explicit opt-in (Security topic, docutils security guide):

DJANGO_DOCUTILS_LIB_RST = {
    "allow_unsafe_docutils_settings": True,
    "docutils": {
        "raw_enabled": True,
        "file_insertion_enabled": True,
    },
}

More information

Docs Build Status Code Coverage

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_docutils-0.30.1.tar.gz (206.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_docutils-0.30.1-py3-none-any.whl (50.6 kB view details)

Uploaded Python 3

File details

Details for the file django_docutils-0.30.1.tar.gz.

File metadata

  • Download URL: django_docutils-0.30.1.tar.gz
  • Upload date:
  • Size: 206.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_docutils-0.30.1.tar.gz
Algorithm Hash digest
SHA256 fa6bb4c3c477653024a459700d926d6557494a624c0650e50082e384defbbcd8
MD5 f491f7eb962fbee7a86469a44c2d30ed
BLAKE2b-256 314c1a8f52ade5a9be1c9945712bb95f7d037d31a0743fb0554b546838cab912

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_docutils-0.30.1.tar.gz:

Publisher: tests.yml on tony/django-docutils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_docutils-0.30.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_docutils-0.30.1-py3-none-any.whl
Algorithm Hash digest
SHA256 092a55930729eee789eabe1d354694ee573cf935069737de59835633c8a362f1
MD5 3fcf7319d02bf8f5a0188f727eca57f0
BLAKE2b-256 0f3a8604ec6aae09d2ea282315467e7660e1fb781e063db8be21890448787a22

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_docutils-0.30.1-py3-none-any.whl:

Publisher: tests.yml on tony/django-docutils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page