Skip to content

Enhance 404 error page by adding search form and loading additional docs tags #1923

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
16 changes: 13 additions & 3 deletions djangoproject/templates/404.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{% extends 'base_error.html' %}
{% load i18n %}
{% load i18n docs %}

{% block title %}{% translate "Page not found" %}{% endblock %}

{% block header %}<h1>404</h1>{% endblock %}
{% block header %}
<div class="copy-banner">
<div class="container--flex container--flex--wrap--mobile">
<h1>404</h1>
{% if request.host.regex == 'docs' %}
{% search_form %}
{% endif %}
</div>
</div>
{% endblock %}

{% block content %}
<h2>{% translate "Page not found" %}</h2>
Expand All @@ -12,7 +21,8 @@ <h2>{% translate "Page not found" %}</h2>
{% blocktranslate trimmed %}
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>.
{% endblocktranslate %}</p>
{% endblocktranslate %}
</p>

{% url 'homepage' as homepage_url %}
<p>
Expand Down
17 changes: 13 additions & 4 deletions docs/templatetags/docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,23 @@
@register.inclusion_tag("docs/search_form.html", takes_context=True)
def search_form(context):
request = context["request"]
version = ""
lang = ""
exception = context.get("exception", "")
if exception:
lang = context["LANGUAGE_CODE"]
version = context["DOCS_VERSION"]
else:
version = context["version"]
lang = context["lang"]
release = DocumentRelease.objects.get_by_version_and_lang(
context["version"],
context["lang"],
version,
lang,
)
return {
"form": DocSearchForm(request.GET, release=release),
"version": context["version"],
"lang": context["lang"],
"version": version,
"lang": lang,
}


Expand Down