theme theme-name没有在狮身人面像中自定义主题的“ theme”设置?

问题描述

我想为python-sphinx创建自己的主题-mytheme

tree project
project
├── build
├── make.bat
├── Makefile
├── mytheme
│   ├── static
│   │   └── style.css
│   └── theme.conf
└── source
    └── conf.py

theme.conf中的内容:

cat  project/mytheme/theme.conf
[theme]
inherit = default
stylesheet = style.css

同意project/source/conf.py

cat project/source/conf.py
def setup(app):
    app.add_stylesheet('static/style.css')
    app.add_html_theme('mytheme',os.path.abspath(os.path.dirname(__file__)))

html_theme = 'mytheme'  
html_theme_path = ['.'] 

现在让我们在源代码中创建所有* .rst文件。

cd project
make html
Running Sphinx v2.4.4
loading pickled environment... done

Theme error:
theme 'mytheme' doesn't have "theme" setting
Makefile:19: recipe for target 'html' failed
make: *** [html] Error 2

如何修复?

解决方法

您使用两种互斥的方法-使用文件系统中的本地主题,并同时注册主题(作为以Python PyPI软件包分发的主题)。

如果您希望主题成为Sphinx项目的一部分,则此类特定于项目的主题的好去处是_themes/在带有conf.py的目录中,并设置html_theme = "mytheme"和{{1 }}中。

html_theme_path = ["_themes"]

(从https://blog.documatt.com/sphinx-theming/themes.html#project-specific-themes借来)

完全删除区块

_themes/
    mytheme/
        static/
            css/
                main.css
        theme.conf
        layout.html
conf.py
index.rst
second.rst
third.rst
...

def setup(app): app.add_stylesheet('static/style.css') app.add_html_theme('mytheme',os.path.abspath(os.path.dirname(__file__))) 是用于打包分发的主题。 add_html_theme()用于添加其他(而不是替换现有的)样式表。主题的主要样式表位于其theme.conf add_stylesheet()选项中。

我在您的示例中看到的最后一个问题是您的主题继承自stylesheet主题。它可以工作,看起来它是default主题(https://www.sphinx-doc.org/en/master/usage/theming.html#builtin-themes)的旧名称,但是使用其正式名称-classic

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...