-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Allow custom 404.html on projects #5130
Conversation
readthedocs/core/views/__init__.py
Outdated
|
||
if os.path.exists(fullpath): | ||
log.debug('Serving custom 404.html page for project: %', project.slug) | ||
r = HttpResponse(open(fullpath).read(), content_type='text/html') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we want to serve this file from Django or we prefer to use the X-Accel-Redirect
header here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, I think this is a bug (or a potential bug). I did the same at https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/core/views/serve.py#L269 but, what happen if this file is too big, for example?
I suppose that we should rely on NGINX to serve them.
I'd like to get some opinions here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main issue here is that it doesn't work locally. We should likely have it do Nginx when DEBUG=False, and serve locally when DEBUG=True.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it should perhaps respect PYTHON_MEDIA instead of DEBUG
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, 404 handler is not called at all on DEBUG=True
, so we will need DEBUG=False
anyway to get at this point.
I agree that it should rely on PYTHON_MEDIA
only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using readthedocs.core.views.serve._serve_file
that does this for us ;)
readthedocs/core/views/__init__.py
Outdated
filename = filename[1:] | ||
|
||
if version.privacy_level == PRIVATE: | ||
symlink = PrivateSymlink(project) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do something special with private versions? I don't think so, but I'm not sure.
readthedocs/core/views/__init__.py
Outdated
@@ -124,7 +129,36 @@ def server_error_404(request, exception=None, template_name='404.html'): # pyli | |||
) | |||
else: | |||
return response | |||
r = render(request, template_name) | |||
|
|||
project, path = project_and_path_from_request(request, request.get_full_path()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function comes from readthedocs.redirects.utils
but we are not using it here for any redirect. This may worth a refactor since this function is called here and also inside of get_redirect_response
some lines above.
readthedocs/core/views/__init__.py
Outdated
r = render(request, template_name) | ||
|
||
project, path = project_and_path_from_request(request, request.get_full_path()) | ||
version_slug = project.get_default_version() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fails when a 404 is generated from RTD itsefl because project
is None
, not a subdomain: http://localhost:8000/pagenotfound
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking on writing a special serve_error_404
for subdomains only and use it only on urls/subdomain.py
. Any other idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, we shouldn't replace the default 404 for RTD, just for subdomains.
docs/guides/custom-404-page.rst
Outdated
|
||
In case you want to follow the same style for the 404 page than your theme, you can either: | ||
|
||
1. manually copy the source of any already rendered pages or, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't recommend this, but just point to the extension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this item and the whole "Manually creation" section.
@humitos we should get this put together and shipped. |
We talked about installing the |
This is an example of what is generated automatically by Read the Docs using It keeps the theme style, also maintains the flyout menu and all the toctree links in the left (we may want to remove the later since could not be the same among versions)
|
Serve `404.html` from default version configured in the project if exists.
Co-Authored-By: humitos <humitos@gmail.com>
Co-Authored-By: humitos <humitos@gmail.com>
Co-Authored-By: humitos <humitos@gmail.com>
48a1f55
to
c25509c
Compare
I think it's probably time to retire the ASCII art, and just use a normal 404 page. We can keep it for the main site, but it feels weird to inject into users docs. We should do something a bit more default and with less personality, since we don't know the style of the docs we're inserting into. |
9d819f6
to
f7ce417
Compare
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.
f7ce417
to
9ac46ef
Compare
…age" This reverts commit 9ac46ef.
It uses the external sphinx-notfound-page extension for this.
I followed what we discussed and this PR is ready to review again and probably merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good
<p>Try using the search box or go to the homepage.</p> | ||
''', | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just for the future, right? We need to add the extension if we want it to do anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just of our docs to start testing it.
The extension is installed in our requirements.
I can remove it if you consider that it's best to start testing this in another dumb project, though.
We had a discussion about this and we arrange on:
404.html
from the root of the version is currently visited if exists.404.html
page can be created manually or via the extesionsphinx-notfound-page
.Once the extension gets stable, we will include it in the build process and we will be generating better 404 pages for all the project without user action. Allowing the user to customize the default page if they prefer.
I tested this locally and it worked. I had to override some settings so Django calls
handler_404
:after running
runserver
you can access to any not found page and see the custom one if the project has one.Closes #353