Skip to content

Commit 2673305

Browse files
authored
Merge pull request #5754 from rtfd/humitos/404-htmldir-builder
Serve 404/index.html file for htmldir Sphinx builder
2 parents 9ca5858 + d704a43 commit 2673305

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

readthedocs/core/views/__init__.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def server_error_404_subdomain(request, template_name='404.html'):
145145
the Docs default page (Maze Found) is rendered by Django and served.
146146
"""
147147

148-
def resolve_404_path(project, version_slug=None, language=None):
148+
def resolve_404_path(project, version_slug=None, language=None, filename='404.html'):
149149
"""
150150
Helper to resolve the path of ``404.html`` for project.
151151
@@ -159,7 +159,7 @@ def resolve_404_path(project, version_slug=None, language=None):
159159
project,
160160
version_slug=version_slug,
161161
language=language,
162-
filename='404.html',
162+
filename=filename,
163163
subdomain=True, # subdomain will make it a "full" path without a URL prefix
164164
)
165165

@@ -197,16 +197,17 @@ def resolve_404_path(project, version_slug=None, language=None):
197197
# Firstly, attempt to serve the 404 of the current version (version_slug)
198198
# Secondly, try to serve the 404 page for the default version (project.get_default_version())
199199
for slug in (version_slug, project.get_default_version()):
200-
basepath, filename, fullpath = resolve_404_path(project, slug, language)
201-
if os.path.exists(fullpath):
202-
log.debug(
203-
'serving 404.html page current version: [project: %s] [version: %s]',
204-
project.slug,
205-
slug,
206-
)
207-
r = static_serve(request, filename, basepath)
208-
r.status_code = 404
209-
return r
200+
for tryfile in ('404.html', '404/index.html'):
201+
basepath, filename, fullpath = resolve_404_path(project, slug, language, tryfile)
202+
if os.path.exists(fullpath):
203+
log.debug(
204+
'serving 404.html page current version: [project: %s] [version: %s]',
205+
project.slug,
206+
slug,
207+
)
208+
r = static_serve(request, filename, basepath)
209+
r.status_code = 404
210+
return r
210211

211212
# Finally, return the default 404 page generated by Read the Docs
212213
r = render(request, template_name)

0 commit comments

Comments
 (0)