Skip to main content

Docutils (a.k.a. reStructuredText, reST, RST) support for django.

Project description

django-docutils · Python Package License

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

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 %}
# hey
# how's it going
A. hows
B. it

C. going
D. today

**hi**
*hi*
{% endrst %}

Template filter

In your template:

{% load django_docutils %}
{% filter rst %}
# hey
# how's it going
A. hows
B. it

C. going
D. today

**hi**
*hi*
{% 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": {
        "raw_enabled": True,
        "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"]
}

More information

  • Python 3.9+
  • Django 4.2+

Docs Build Status Code Coverage

Project details


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.28.0.tar.gz (132.9 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.28.0-py3-none-any.whl (44.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_docutils-0.28.0.tar.gz
  • Upload date:
  • Size: 132.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for django_docutils-0.28.0.tar.gz
Algorithm Hash digest
SHA256 a5f1f670aedef7dc28b1317968ccb7b1a8c4863b4624b16ef065e63b192cd58b
MD5 ce0123558ae466d58fe5a0afc71d73c4
BLAKE2b-256 bd7dec259e916911507005a39631660333f7ab990aa865f612dc483d694f87d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_docutils-0.28.0-py3-none-any.whl
Algorithm Hash digest
SHA256 57a0f79c0d8b27e01319fb4c25eff80170329cd9ddec3a89e284e19564d570d7
MD5 e49861e45a46a8e4740f7ee930ea31fa
BLAKE2b-256 e3ea525caeb819c4ab96126ef19be482e21b658c3ed2fdf281f8b2ba22d30e8d

See more details on using hashes here.

Supported by

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