Skip to content

Commit 9ac46ef

Browse files
committed
Use sphinx-notfound-page by default to create a generic 404 page
We use the sphinx-notfound-page extension to create a generic page for each project. By default we use the same Maze Found ASCII art, but the user can customize it by defining specific configs from the sphinx-notfound-page.
1 parent 689ec78 commit 9ac46ef

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

readthedocs/core/views/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def server_error_404(request, exception=None, template_name='404.html'): # pyli
132132
return response
133133

134134
# Try to serve custom 404 pages if it's a subdomain/cname
135-
if request.subdomain or request.cname:
135+
if getattr(request, 'subdomain', False) or getattr(request, 'cname', False):
136136
return server_error_404_subdomain(request, template_name)
137137

138138
# Return the default 404 page generated by Read the Docs

readthedocs/doc_builder/python_environments.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def install_core_requirements(self):
307307
),
308308
'sphinx-rtd-theme<0.5',
309309
'readthedocs-sphinx-ext<0.6',
310+
'sphinx-notfound-page',
310311
])
311312

312313
cmd = copy.copy(pip_install_cmd)
@@ -429,7 +430,10 @@ def install_core_requirements(self):
429430
if self.config.doctype == 'mkdocs':
430431
pip_requirements.append('mkdocs')
431432
else:
432-
pip_requirements.append('readthedocs-sphinx-ext')
433+
pip_requirements.extend([
434+
'readthedocs-sphinx-ext',
435+
'sphinx-notfound-page',
436+
])
433437
requirements.extend(['sphinx', 'sphinx_rtd_theme'])
434438

435439
cmd = [
@@ -443,7 +447,7 @@ def install_core_requirements(self):
443447
cmd.extend(requirements)
444448
self.build_env.run(
445449
*cmd,
446-
cwd=self.checkout_path # noqa - no comma here in py27 :/
450+
cwd=self.checkout_path,
447451
)
448452

449453
pip_cmd = [

readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl

+13
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,16 @@ if 'extensions' in globals():
140140
extensions.insert(0, "readthedocs_ext.readthedocs")
141141
else:
142142
extensions = ["readthedocs_ext.readthedocs"]
143+
144+
145+
# Define default 404 page body
146+
if 'notfound_context' not in globals():
147+
notfound_context = {
148+
'body': '''
149+
<h1>Page not found</h1>
150+
151+
<p>Sorry, we couldn't find that page.</p>
152+
153+
<p>Try using the search box or go to the homepage.</p>
154+
''',
155+
}

readthedocs/rtd_tests/tests/test_doc_building.py

+2
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,7 @@ def test_install_core_requirements_sphinx(self, checkout_path):
12291229
'sphinx',
12301230
'sphinx-rtd-theme',
12311231
'readthedocs-sphinx-ext',
1232+
'sphinx-notfound-page',
12321233
]
12331234
requirements = self.base_requirements + requirements_sphinx
12341235
args = self.pip_install_args + requirements
@@ -1356,6 +1357,7 @@ def test_install_core_requirements_sphinx_conda(self, checkout_path):
13561357
pip_requirements = [
13571358
'recommonmark',
13581359
'readthedocs-sphinx-ext',
1360+
'sphinx-notfound-page',
13591361
]
13601362

13611363
args_pip = [

0 commit comments

Comments
 (0)