Skip to content

Commit

Permalink
Move technical_500 template paths to class-level variables
Browse files Browse the repository at this point in the history
This allows effortless replacement of the debugging templates
without having to copy-paste the `get_traceback_html` and
`get_traceback_text` functions into a deriving class.
  • Loading branch information
akx committed Jan 30, 2020
1 parent 8c0c023 commit 45fdeaa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions django/views/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ def get_traceback_frame_variables(self, request, tb_frame):

class ExceptionReporter:
"""Organize and coordinate reporting on exceptions."""

html_template_path = Path(CURRENT_DIR, 'templates', 'technical_500.html')
text_template_path = Path(CURRENT_DIR, 'templates', 'technical_500.txt')

def __init__(self, request, exc_type, exc_value, tb, is_email=False):
self.request = request
self.filter = get_exception_reporter_filter(self.request)
Expand Down Expand Up @@ -321,14 +325,14 @@ def get_traceback_data(self):

def get_traceback_html(self):
"""Return HTML version of debug 500 HTTP error page."""
with Path(CURRENT_DIR, 'templates', 'technical_500.html').open(encoding='utf-8') as fh:
with self.html_template_path.open(encoding='utf-8') as fh:
t = DEBUG_ENGINE.from_string(fh.read())
c = Context(self.get_traceback_data(), use_l10n=False)
return t.render(c)

def get_traceback_text(self):
"""Return plain text version of debug 500 HTTP error page."""
with Path(CURRENT_DIR, 'templates', 'technical_500.txt').open(encoding='utf-8') as fh:
with self.text_template_path.open(encoding='utf-8') as fh:
t = DEBUG_ENGINE.from_string(fh.read())
c = Context(self.get_traceback_data(), autoescape=False, use_l10n=False)
return t.render(c)
Expand Down

0 comments on commit 45fdeaa

Please sign in to comment.