跳转到主要内容

Docutils(又称reStructuredText、reST、RST)对Django的支持。

项目描述

django-docutils · Python Package License

docutils(又称reStructuredText / rst / reST)对Django的支持。

快速入门

安装django-docutils

$ pip install django-docutils

接下来,将django_docutils添加到您的设置文件中的INSTALLED_APPS

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

模板标签

在您的模板中

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

C. going
D. today

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

模板过滤器

在您的模板中

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

C. going
D. today

**hi**
*hi*
{% endfilter %}

模板引擎(基于类的视图)

您还可以使用基于类的视图来渲染reStructuredText(reST)。

如果您想将reStructuredText作为Django模板引擎使用,则不需要在INSTALLED_APPS中,而是将此添加到您的设置中的TEMPLATES变量

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

现在Django将能够扫描.rst文件并处理它们。在您的视图中

from django_docutils.views import DocutilsView

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

设置

# 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"]
}

更多信息

  • Python 3.8+
  • Django 3.2+

Docs Build Status Code Coverage

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分布

django_docutils-0.26.0.tar.gz (33.6 kB 查看哈希)

上传时间 源代码

构建分布

django_docutils-0.26.0-py3-none-any.whl (44.8 kB 查看哈希)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面