Django中的Sphinx文档

Tom*_*mas 4 django jinja2 python-sphinx

我目前正在将sphinx生成的文档集成到我的Django应用程序中。我希望文档扩展我的应用程序模板。Sphinx生成的HTML应该如下所示

{% extends "base.html" %}
{% block content %}
...
Run Code Online (Sandbox Code Playgroud)

我的狮身人面像主题模板看起来是:

{{ '{% extends "base.html" %}' }}
{{ '{% block content %}' }}
...
Run Code Online (Sandbox Code Playgroud)

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

S.L*_*ott 5

我们使用JSONHTMLBuilder

http://sphinx.pocoo.org/builders.html#sphinx.builders.html.JSONHTMLBuilder

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

http://sphinx.pocoo.org/builders.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 )
Run Code Online (Sandbox Code Playgroud)

类似的东西可以工作。