【问题标题】:Sphinx: How set the right path for html_static_path in config.py?Sphinx:如何在 config.py 中为 html_static_path 设置正确的路径?
【发布时间】:2022-01-17 10:15:04
【问题描述】:

我是初学者,所以也许这个问题听起来很愚蠢,但无论如何:

我正在使用 sphinx,我想在 config.py 文件中设置 html_static_path 变量。

默认是:

html_static_path = ['_static']

我的项目设置是:

docs/
    build/
         doctrees
         html/
             _static/ 
    source/
          conf.py

sphinx 文档说我需要设置相对于这个目录的路径,即来自 conf.py 的 rel 路径。所以我尝试了:

html_static_path = ['..\build\html\source\_static']

我尝试设置绝对路径。

但我仍然收到警告:

警告:html_static_path 条目“build\html\source\_static”不存在

也许值得一提:

我的 conf.py 文件的“路径设置”是:

import os
import sys
sys.path.insert(0, os.path.abspath('..'))
sys.setrecursionlimit(1500)

你能帮帮我吗?我已经尝试了所有我能想到的路径组合。 谢谢!

【问题讨论】:

  • 要摆脱错误信息,只需在source 目录中添加一个_static 子目录即可。并删除html_static_path = ['..\build\html\source\_static']
  • 请注意,您的“路径设置”与html_static_path 无关。

标签: python path python-sphinx


【解决方案1】:

构建目录是在您构建文档后创建的,这就是您收到该错误的原因。当您制作文档时,Sphinx 会将静态目录从您的源位置(由 html_static_path 定义)复制到构建位置。

创建一个新目录source/_static 并在其中放置所有静态资源。

conf.py 中的值更改为:

html_static_path = ["_static"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-11
    • 2013-11-25
    • 1970-01-01
    • 2014-07-26
    • 2019-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多