404 page#
Because Sphinx does not create a 404 page by default, you can use the sphinx-notfound-page extension for 404 pages. While originally developed to be used with Read the Docs, this extension can be used in other hosting services. For more information, see the extension’s documentation.
Install the extension#
Install and enable the sphinx-notfound-page
extension with:
python -m pip install sphinx-notfound-page
Consider adding this extension to your requirements_doc.txt
file.
Add the extension to the conf.py
file#
After installing the sphinx-notfound-page
extension, add it to
your conf.py
file:
# Add the extension
extensions = [
...,
"notfound.extension",
]
Configure your 404 page#
You can use the default 404 page that the ansys-sphinx-theme
package supplies
or create and use a custom 404 page.
Use the default 404 page#
To use the default 404 page, you can use the generate_404
function in the
ansys_sphinx_theme
module to create and use a custom cover page:
from ansys_sphinx_theme import generate_404
# Configure sphinx-notfound-page
notfound_context = {
'body': generate_404(<organisation_which_the_project_belongs_to>,
<name_of_the_project>,
<mail_id_for_the_project>,
<name_of_team_managing_the_project>
)
}
Create and use a custom 404 page#
To create and use a custom 404 page, do the following:
Create a
404.rst
file next to theconf.py
file.To suppress the spurious
document isn't included in any toctree
Sphinx warning, include the:orphan:
attribute at the top of this404.rst
file::orphan: Error 404 Not Found =================== The page you are requesting does not exist.
Update the
notfound_template
variable in theconf.py
to the location of your404.rst
file:# Configure sphinx-notfound-page notfound_template = "path/to/404.rst"