我目前正在我的 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/