django - Django 中的 Sphinx 文档

标签 django python-sphinx jinja2

我目前正在我的 Django 应用程序中集成 sphinx 生成的文档。我想要文档来扩展我的应用程序模板。 Sphinx 生成的 HTML 应该是这样的

{% extends "base.html" %}
{% block content %}
...

我的狮身人面像主题模板看起来是:
{{ '{% extends "base.html" %}' }}
{{ '{% block content %}' }}
...

有没有更好的方法来实现这一目标?

最佳答案

我们使用 JSONHTMLBuilder:

https://www.sphinx-doc.org/en/master/usage/builders/index.html#sphinxcontrib.serializinghtml.jsonhtmlbuilder

JSON 文件的内容可以更轻松地插入到页面中。

https://www.sphinx-doc.org/en/master/usage/builders/index.html#serialization-builder-details

您阅读了 JSON 文档,然后将其呈现到您的模板中。

def someView( request, topic ):
    # use settings.SOME_DIRECTORY + path info to find the JSON file
    with something as source:
        doc= json.loads( source )
    render_to_response( 'page.template', doc )

类似的东西可以工作。

关于django - Django 中的 Sphinx 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5097676/

相关文章:

mysql - Django ORM : Tried to do inner join with foreign key but causes FieldError

python - 如何在 jinja html 模板中发送图像?

Jquery XHR 导致 dom 更改通过刷新等持续存在

django - 如何更改序列化程序中持续时间字段值的格式?

python - 如何从值 models.IntegerChoices 中获取标签

django - 如何使用 ManifestStaticFilesStorage 从散列中排除路径

python-sphinx - 添加对另一个页面中的副标题或 anchor 的交叉引用

python - Sphinx 文档常量替换

python - 狮身人面像 : How set the right path for html_static_path in config. py?

javascript - 如何将javascript值设置为jinja变量