Sphinx中index.rst混合include指令与rst文件引用失效问题
Hey there, I see exactly what's going wrong here! The issue comes from mixing up how the .. include:: directive works and how to add additional pages to your Sphinx documentation. Let's break this down and fix it.
Why Your Current Setup Fails
The .. include:: directive is designed to pull the content of one specific file into the current document. When you added static and about right after .. include:: list.rst, you're invalidating the syntax—Sphinx doesn't recognize those extra filenames as part of the include directive, and they aren't valid standalone RST commands either. That's why your setup broke.
Solution 1: Include Multiple Files Directly in index.rst
If you want the content of static.rst and about.rst to be embedded directly into the index.rst page (so all content lives on one page), you need to use a separate .. include:: directive for each file:
Project Test ============================ .. include:: list.rst .. include:: static.rst .. include:: about.rst
This will pull the content of all three files into your index page in the order you list them.
Solution 2: Add static and about as Separate Pages (Using toctree)
If you want static and about to be distinct pages in your documentation (with their own entries in the navigation menu), you should use Sphinx's toctree directive instead of trying to list them after the include. Here's how to set that up:
Project Test ============================ .. include:: list.rst .. toctree:: :maxdepth: 2 :caption: Additional Pages static about
This will:
- Keep the content of
list.rstembedded in your index page. - Add
static.rstandabout.rstas separate pages under the "Additional Pages" section in your documentation's navigation.
Make sure that static.rst and about.rst exist in the same directory as index.rst (or adjust the paths accordingly if they're in subfolders).
Pick the solution that matches what you're trying to achieve—either embedding all content into one page, or creating separate navigable pages.
内容的提问来源于stack exchange,提问作者nyi

