【问题标题】:How to customize sphinx.ext.autosummary rst template?如何自定义 sphinx.ext.autosummary rst 模板?
【发布时间】:2015-01-26 09:24:56
【问题描述】:

Here 在 Sphinx 的文档中说可以重新定义这些模板。 所以我尝试将module.rst 从/site-packages/sphinx/ext/autosummary 复制到source/_templates/autosummary(也尝试了source/_templates),并进行了一些细微的更改。但是在我重新生成文档后,什么都没有改变。

也许我应该在.. autosummary:: 标签中添加一些特定选项来指定自定义模板目录? (在 conf.py 目录中设置正确,sphinx 参见html 模板)

UPD:源代码:https://github.com/actionless/wooper/blob/master/docs.sh

【问题讨论】:

  • 源代码链接失效。
  • @gerrit,是的,那是 4 年前,文档结构从那一刻起发生了变化

标签: python python-sphinx


【解决方案1】:

如果您执行以下操作,它应该会起作用:

  1. 确保在conf py中templates_path配置变量的值设置为['_templates']。
  2. 将自定义模板放在_templates 子目录中。
  3. 使用:template: 选项:

    .. autosummary::
      :template: mytemplate.rst
    

【讨论】:

  • 您确定不需要任何其他操作吗?我做了同样的事情,但似乎'_templates'目录的内容像源文件一样被处理(并且sphinx-build抱怨它就像错误的源代码一样)。将其添加到 exclude-pattern 可以使这些警告静音,但 'autosummary' 仍然表现得像没有指定 ":template:" 参数e
  • 顺便说一句,这里是源代码:github.com/actionless/wooper/blob/debug-autosummary/docs.sh
  • 据我所知,您没有像sphinx-doc.org/ext/autosummary.html?highlight=stub 中所述生成“存根”页面。在这种情况下,没有可以自定义的模板。
  • 看来我需要添加autosummary_generate 选项才能使事情正常进行?
【解决方案2】:

已编辑:我最初在这里发布了对错误问题的答案。但是,在这里也可能有所帮助。

可以通过将自定义文件添加到_templates 文件夹中来“否决”默认模板。例如,如果您想更改调用 autosummary 指令时使用的类的模板,请在此路径下创建自定义 class.rst 文件:

  • _templates/autosummary/class.rst

应该自动获取,无需明确指定:template:。

【讨论】:

  • 这不应该是stackoverflow.com/q/67899730/407651的答案吗?
  • 是的,确实如此。对太多浏览器点击 ups 感到困惑。在这里调整了我的错误帖子,因为它也可能适用于这篇帖子。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多