#32997: Errors in 404 templates are hard to debug
---------------------------------+--------------------------------------
Reporter: jooadam | Owner: (none)
Type: Bug | Status: closed
Component: Error reporting | Version: 3.2
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Carlton Gibson):
* status: new => closed
* resolution: => wontfix
Comment:
Hi. Thanks for the extra info.
> I have a custom 404.html template...
So custom error templates should (in general) be entirely straight-
forward, in order to be certain not to raise an error themselves.
(Adding complexity to the default error handlers here isn't something we
want to get into.)
In your case, where you want a more complex template, it's incumbent upon
you to also
[https://docs.djangoproject.com/en/3.2/topics/http/views/#s-id1 customise
the error views] to ensure any possible exceptions are appropriately dealt
with.
Minimally, you could add logging if you introduce the possibility of an
exception:
{{{
import logging
from django.views.defaults import page_not_found
logger = logging.getLogger(__name__)
def custom_page_not_found(request, exception, template_name='404.html'):
try:
page_not_found(request, exception, template_name)
except:
logger.exception("ERROR OCCURRED")
raise
handler404 = 'foo.urls.custom_page_not_found'
}}}
Your traceback is then available.
See also the [https://docs.djangoproject.com/en/3.2/topics/http/views
/#testing-custom-error-views Testing custom error views] section, that
will enable you to make sure your error handling works before putting it
live.
--
Ticket URL: <https://code.djangoproject.com/ticket/32997#comment:7>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.6dbd588f1174311125479ed291296c89%40djangoproject.com.