Use context processor for 500 page

By default, Django doesn't run any context processors for server errors,
to make the error path as simple as possible. However, this has the
downside that our template does not load correctly. To fix this, I added
a custom 500 error handler, which will run the context processor.

Fixes: #2736
This commit is contained in:
Wesley Aptekar-Cassels 2023-03-13 03:42:09 -04:00
parent cca20f4834
commit 0b9e4d617e
3 changed files with 12 additions and 0 deletions

View file

@ -773,3 +773,6 @@ urlpatterns = [
),
path("guided-tour/<tour>", views.toggle_guided_tour),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# pylint: disable=invalid-name
handler500 = "bookwyrm.views.server_error"

View file

@ -165,3 +165,4 @@ from .annual_summary import (
summary_add_key,
summary_revoke_key,
)
from .server_error import server_error

View file

@ -0,0 +1,8 @@
"""custom 500 handler to enable context processors"""
from django.template.response import TemplateResponse
def server_error(request):
"""server error page"""
return TemplateResponse(request, "500.html")