Skip to content

Serve 404/index.html file for htmldir Sphinx builder #5754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions readthedocs/core/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def server_error_404_subdomain(request, template_name='404.html'):
the Docs default page (Maze Found) is rendered by Django and served.
"""

def resolve_404_path(project, version_slug=None, language=None):
def resolve_404_path(project, version_slug=None, language=None, filename='404.html'):
"""
Helper to resolve the path of ``404.html`` for project.

Expand All @@ -159,7 +159,7 @@ def resolve_404_path(project, version_slug=None, language=None):
project,
version_slug=version_slug,
language=language,
filename='404.html',
filename=filename,
subdomain=True, # subdomain will make it a "full" path without a URL prefix
)

Expand Down Expand Up @@ -197,16 +197,17 @@ def resolve_404_path(project, version_slug=None, language=None):
# Firstly, attempt to serve the 404 of the current version (version_slug)
# Secondly, try to serve the 404 page for the default version (project.get_default_version())
for slug in (version_slug, project.get_default_version()):
basepath, filename, fullpath = resolve_404_path(project, slug, language)
if os.path.exists(fullpath):
log.debug(
'serving 404.html page current version: [project: %s] [version: %s]',
project.slug,
slug,
)
r = static_serve(request, filename, basepath)
r.status_code = 404
return r
for tryfile in ('404.html', '404/index.html'):
basepath, filename, fullpath = resolve_404_path(project, slug, language, tryfile)
if os.path.exists(fullpath):
log.debug(
'serving 404.html page current version: [project: %s] [version: %s]',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

('Serving %s ... ', tryfile, ...)

project.slug,
slug,
)
r = static_serve(request, filename, basepath)
r.status_code = 404
return r

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