Class-based view¶
Use DocutilsView when a reStructuredText file
should behave like a Django view page. Django chooses the outer template,
django-docutils renders the .rst source, and the view passes the rendered
HTML as content.
For applications that want Django to load .rst files through a template
backend, DocutilsTemplates provides the
docutils engine.
See also
Important
Both entry points use locked-down docutils defaults. See Security before serving user-authored RST or enabling trusted-content overrides.
Setup¶
You do not need INSTALLED_APPS for the backend-only path. Add the docutils
backend to TEMPLATES instead:
TEMPLATES = [
# ... Other engines
{
"NAME": "docutils",
"BACKEND": "django_docutils.template.DocutilsTemplates",
"DIRS": [],
"APP_DIRS": True,
}
]
Render a view¶
With the backend configured, your view points at an RST template:
from django_docutils.views import DocutilsView
class HomeView(DocutilsView):
template_name = "base.html"
rst_name = "home.rst"
yourapp/templates/home.rst:
hey
---
hi
##
A. hows
B. it
C. going
D. today
**hi**
*hi*
yourapp/templates/base.html:
{{content}}
Output:
<div class="document" id="hey">
<h1 class="title">hey</h1>
<h2 class="subtitle" id="hi">hi</h2>
<ol class="upperalpha simple">
<li>hows</li>
<li>it</li>
<li>going</li>
<li>today</li>
</ol>
<p><strong>hi</strong>
<em>hi</em></p>
</div>
Explore the API