python - Sphinx add_config_value 不添加变量

标签 python django python-sphinx django-sphinx

尝试根据此处的文档添加一个简单的 true/false 值:

http://sphinx-doc.org/ext/ifconfig.html

在我的 conf.py 文件中:

extensions = ['sphinx.ext.todo', 'sphinx.ext.ifconfig']

# Custom variables
def setup(app):
    app.add_config_value('responsiveenabled', True, True)

在我的 grids.rst 文件(描述如何设置引导网格的页面)中,我有这个:

.. ifconfig:: responsiveenabled

Blah blah blah.

我得到的错误是:

NameError: name 'responsiveenabled' is not defined

我是否需要在 responsiveenabled 之后添加一些内容,例如“in (...)”?我想让它与我正在编写的文档版本无关。

最佳答案

你的 conf.py 文件应该是:

extensions = ['sphinx.ext.todo', 'sphinx.ext.ifconfig']

# Custom variables
def setup(app):
    app.add_config_value('responsiveenabled', True, True)

responsiveenabled = True

我知道它应该是默认值,但我无法让它工作 没有初始化。

然后你就可以使用了

.. ifconfig:: responsiveenabled

   text included if the config variable is set

text always included

关于python - Sphinx add_config_value 不添加变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14060582/

相关文章:

python - 如何在 Pandas 中获得 "group by"单元格值?

Python while循环没有中断

html - 在 HTML/CSS 中的一行上的特定点上显示大小调整按钮

python - ImportError : No module named mysite. 设置(Django)

python - 如何在 sphinx argparse 或自动编程中将 "description"解释为重组文本?

python - 清除 Pyramid 中的设置工具缓存?

python - 隐藏pygame显示

python - 在 Wagtail 管理员中更改页面所有者

css - Sphinx 不会覆盖 css 样式表

terminal - 如何在 Sphinx 中显示终端/外壳代码片段?