Why the html file converted from rst file containing question mark can't displayed on browser when to click the catalog?

Issue 1 is actually not an issue, it is the normal behaviour of Sphinx: The displayed title is not the filename but the top level title of the ResT document, which is ended with a question mark in both case. See the Table of contents > .. toctree:: > Entries section of this page which states:

Document titles in the toctree will be automatically read from the title of the referenced document.

If you need to be convinced, just change the title of any of the document, rebuild the HTML and see.


Issue 2 is caused by the presence of a non urlencoded question mark in the href of the link. In an url, the question mark means the start of a query string.

That is trying to access What does "_" in Python mean in a for-loop?.html, means requesting the What does "_" in Python mean in a for-loop HTML document, giving it a .html parameter. And obviously, the requested document is not found since it does not exist.

In the address bar of your browser, you can replace the question mark by its urlencoded form %3F, and observe it works then.

I did not find any way to make sphinx automatically urlencode document names in link's href (it actually is considered a bug) or any doc clearly expressing naming restriction for ResT documents.

But I know from experience that naming a file with punctuation is often source of problems. I would advice you to rename your document with less exotic characters (slugify them). Naming your ResT document underscore_in_for_loop.rst instead of What does "_" in Python mean in a for-loop?.rst will save you a lot of time and headaches.

And remember that it should not be a problem since, as we seen in the first issue, the document name is used only for the URL.


? is a wildcard for part word matching in URL and hence will be treated as a special character.

wild cards operate with two type of jokers:

  ? - any character  (one and only one)
  * - any characters (zero or more)

For this, You have to Encode the URL

import urllib.parse
>>> urllib.parse.quote(<<url>>)

In Python 3.x, you need to import urllib.parse.quote:

import urllib.parse
urllib.parse.quote(<<url>>)