为什么第一个带问号的文件转成的html文件在点击目录时浏览器无法显示?
Why the html file converted from rst file containing question mark can't displayed on browser when to click the catalog?
请下载文件 simple.7z
并安装到您的 sphinx 中以重现我在此处描述的问题,为了重现它,您可以 运行:
make clean
make html
download and install in your sphinx to reproduce issues
sample/source
中有两篇文章,内容相同,只是标题不同。
cd sample
ls source |grep "for-loop"
What does "_" in Python mean in a for-loop.rst
What does "_" in Python mean in a for-loop?.rst
一个包含?
,另一个不包含?
。
运行宁make html
之后发生了奇怪的事情。
make html
ls build/html|grep "for-loop"
What does "_" in Python mean in a for-loop.html
What does "_" in Python mean in a for-loop?.html
问题 1:
为什么 firefox 将所有显示为 What does “_” in Python mean in a for-loop?
笔记:
"_"
被组合成 “_”
;
没有?
的标题比如What does "_" in Python mean in a for-loop.html
被编译成了What does “_” in Python mean in a for-loop?
,里面加了一个?
?
问题 2:
点击第一个标题What does “_” in Python mean in a for-loop?
,浏览器跳转到状态no url was not found on this server
要单击第二个标题 What does “_” in Python mean in a for-loop?
,它可以正常工作。
请解释我的问题。
?
是 wildcard 用于 URL 中的部分单词匹配,因此将被视为特殊字符。
百搭牌有两种类型的王牌:
? - any character (one and only one)
* - any characters (zero or more)
为此,您必须 Encode the URL
import urllib.parse
>>> urllib.parse.quote(<<url>>)
在Python3.x中,需要导入urllib.parse.quote:
import urllib.parse
urllib.parse.quote(<<url>>)
问题1其实不是问题,是Sphinx的正常行为:显示的标题不是文件名,而是ResT文档的顶级标题,即在这两种情况下都以问号结尾。
请参阅 Table 的内容 > .. toctree:: > Entries 部分 this page 其中指出:
Document titles in the toctree will be automatically read from the title of the referenced document.
如果您需要被说服,只需更改任何文档的标题,重建 HTML 并查看。
问题 2 是由 link 的 href
中存在非 url 编码问号引起的。在 url 中,问号表示 query string.
的开始
即试图访问What does "_" in Python mean in a for-loop?.html
,意思是请求What does "_" in Python mean in a for-loop
HTML文档,给它一个.html
参数。很明显,请求的文档没有找到,因为它不存在。
在您浏览器的地址栏中,您可以用 url 编码形式 %3F
替换问号,然后观察它是否有效。
我没有找到任何方法来自动制作 sphinx url在 link 的 href
(it actually is considered a bug) 或任何明确表达命名限制的文档中编码文档名称用于 REST 文档。
但我从经验中知道,用标点符号命名文件通常是问题的根源。 我建议您用较少的奇异字符重命名您的文档(将它们标记为 slugify)。将 ResT 文档命名为 underscore_in_for_loop.rst
而不是 What does "_" in Python mean in a for-loop?.rst
将为您节省大量时间和麻烦。
请记住,这应该不是问题,因为正如我们在第一期中看到的那样,文档名称仅用于 URL.
请下载文件 simple.7z
并安装到您的 sphinx 中以重现我在此处描述的问题,为了重现它,您可以 运行:
make clean
make html
download and install in your sphinx to reproduce issues
sample/source
中有两篇文章,内容相同,只是标题不同。
cd sample
ls source |grep "for-loop"
What does "_" in Python mean in a for-loop.rst
What does "_" in Python mean in a for-loop?.rst
一个包含?
,另一个不包含?
。
运行宁make html
之后发生了奇怪的事情。
make html
ls build/html|grep "for-loop"
What does "_" in Python mean in a for-loop.html
What does "_" in Python mean in a for-loop?.html
为什么 firefox 将所有显示为 What does “_” in Python mean in a for-loop?
笔记:
"_"
被组合成 “_”
;
没有?
的标题比如What does "_" in Python mean in a for-loop.html
被编译成了What does “_” in Python mean in a for-loop?
,里面加了一个?
?
问题 2:
点击第一个标题What does “_” in Python mean in a for-loop?
,浏览器跳转到状态no url was not found on this server
What does “_” in Python mean in a for-loop?
,它可以正常工作。
请解释我的问题。
?
是 wildcard 用于 URL 中的部分单词匹配,因此将被视为特殊字符。
百搭牌有两种类型的王牌:
? - any character (one and only one)
* - any characters (zero or more)
为此,您必须 Encode the URL
import urllib.parse
>>> urllib.parse.quote(<<url>>)
在Python3.x中,需要导入urllib.parse.quote:
import urllib.parse
urllib.parse.quote(<<url>>)
问题1其实不是问题,是Sphinx的正常行为:显示的标题不是文件名,而是ResT文档的顶级标题,即在这两种情况下都以问号结尾。 请参阅 Table 的内容 > .. toctree:: > Entries 部分 this page 其中指出:
Document titles in the toctree will be automatically read from the title of the referenced document.
如果您需要被说服,只需更改任何文档的标题,重建 HTML 并查看。
问题 2 是由 link 的 href
中存在非 url 编码问号引起的。在 url 中,问号表示 query string.
即试图访问What does "_" in Python mean in a for-loop?.html
,意思是请求What does "_" in Python mean in a for-loop
HTML文档,给它一个.html
参数。很明显,请求的文档没有找到,因为它不存在。
在您浏览器的地址栏中,您可以用 url 编码形式 %3F
替换问号,然后观察它是否有效。
我没有找到任何方法来自动制作 sphinx url在 link 的 href
(it actually is considered a bug) 或任何明确表达命名限制的文档中编码文档名称用于 REST 文档。
但我从经验中知道,用标点符号命名文件通常是问题的根源。 我建议您用较少的奇异字符重命名您的文档(将它们标记为 slugify)。将 ResT 文档命名为 underscore_in_for_loop.rst
而不是 What does "_" in Python mean in a for-loop?.rst
将为您节省大量时间和麻烦。
请记住,这应该不是问题,因为正如我们在第一期中看到的那样,文档名称仅用于 URL.