djangoproject.com
djangoproject.com copied to clipboard
Improve 404 page
Take a broken docs link like: https://docs.djangoproject.com/en/4.2/ref/databasess/ (two "s" chars at the end instead of one).
The 404 page could at least show the docs search bar to make it easy to search for the relevant page.
For bonus points, it could even show search results for the keywords in the URL ("databasess") or show close matches from existing URL's (using e.g. difflib.get_close_matches).
like this?
however i don't thinks what i did is a proper way of doing it, i used same search as in documentation page by making some changes in templatetags/docs.py
def search_form(context):
request = context["request"]
version = context["version"] if "version" in context else context["DJANGO_VERSION"]
lang = context["lang"] if "lang" in context else context["LANGUAGE_CODE"]
release = DocumentRelease.objects.get_by_version_and_lang(
version,
lang,
)
return {
"form": DocSearchForm(request.GET, release=release),
"version": version,
"lang": lang,
}
and in 404.html
{% extends 'base_error.html' %}
{% load docs %}
{% block title %}Page not found{% endblock %}
{% block header-classes %}
container--flex container--flex--wrap--mobile
{% endblock %}
{% block header %}
<h1>404</h1>
{% search_form %}
{% endblock %}
{% block content %}
<h2>Page not found</h2>
<p>Looks like you followed a bad link. If you think it's our fault, please <a href="https://code.djangoproject.com/">let us know</a>.</p>
<p>Here's a link to the <a href="{% url 'homepage' %}">homepage</a>. You know, just in case.</p>
{% endblock %}
A more proper way would be writing a handler for 404? but maybe i should ask permission for it before
@adamchainz I would like to contribute on this issue.
fixed by https://github.com/django/djangoproject.com/pull/1454