You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让Sphinx识别并使用自定义主题?

解决Sphinx无法检测自定义主题的问题

1. 配置主题搜索路径

在docs/conf.py中添加自定义主题的路径配置,让Sphinx能定位到同级的custom_theme目录:

import os
html_theme_path = [os.path.abspath('../')]

2. 修正主题目录结构

Sphinx要求主题的模板文件必须放在_templates子目录下,调整你的文件夹结构为:

.
docs
   conf.py
   makefile
   make.bat
   index.md
custom_theme
   theme.toml
   _templates
      layout.html

3. 确保theme.toml内容合规

检查custom_theme/theme.toml的必填字段是否完整,主题名称必须和conf.py中html_theme的值一致:

[theme]
name = "custom_theme"
version = "0.1.0"
description = "自定义Sphinx主题"

4. 重新构建文档

再次执行你的构建命令即可:

sphinx-autobuild -a docs docs/_build/html --watch custom_theme

内容的提问来源于stack exchange,提问作者Skrillx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 22:45:02