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",
        }
    },
}

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

More information

  • Python 3.8+
  • Django 3.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.20.1.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

django_docutils-0.20.1-py3-none-any.whl (44.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_docutils-0.20.1.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for django_docutils-0.20.1.tar.gz
Algorithm Hash digest
SHA256 863a8e3af870d062ec9c7fd6b571d98b7d799de17bb45007bb80cd5958ce65d7
MD5 bf4c66221c9950ef3079bbcba6eea3a3
BLAKE2b-256 1eabd42a8780b0ac48922f0cc4b8c63d0ed2d48901774983f06c4375a7dc4f67

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for django_docutils-0.20.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a5842288a4752cbc8708264713c5b385bb15b149e226d39e593c1d3f2a681241
MD5 359c26d9871689a20f7ada3cfb8d18f8
BLAKE2b-256 89991f0bc8fa71e6c14a889a2e1083286daed13c972d10d7024e4e020f2b830b

See more details on using hashes here.

Provenance

Supported by

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