diff options
| author | farhan <farhanalirazaazeemi@gmail.com> | 2025-03-21 20:06:12 +0500 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-04-17 08:56:53 +0200 |
| commit | 4a293eff6fb10a04de7c65ed705ca3c6a362a587 (patch) | |
| tree | 88a45a60491e846ca3983e2e1c8ba7b9cc3efe91 /django | |
| parent | 098c8bc99c84e6b09ee0066ed85b216ec63a046a (diff) | |
Fixed #28050 -- Added template name to TemplateSyntaxError.
Diffstat (limited to 'django')
| -rw-r--r-- | django/template/base.py | 8 | ||||
| -rw-r--r-- | django/views/debug.py | 4 |
2 files changed, 11 insertions, 1 deletions
diff --git a/django/template/base.py b/django/template/base.py index e586a27991..140f713add 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -199,6 +199,14 @@ class Template: except Exception as e: if self.engine.debug: e.template_debug = self.get_exception_info(e, e.token) + if ( + isinstance(e, TemplateSyntaxError) + and self.origin.name != UNKNOWN_SOURCE + and e.args + ): + raw_message = e.args[0] + e.raw_error_message = raw_message + e.args = (f"Template: {self.origin.name}, {raw_message}", *e.args[1:]) raise def get_exception_info(self, exception, token): diff --git a/django/views/debug.py b/django/views/debug.py index 425ad296b2..948cdcbf2f 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -414,7 +414,9 @@ class ExceptionReporter: if self.exc_type: c["exception_type"] = self.exc_type.__name__ if self.exc_value: - c["exception_value"] = str(self.exc_value) + c["exception_value"] = getattr( + self.exc_value, "raw_error_message", self.exc_value + ) if exc_notes := getattr(self.exc_value, "__notes__", None): c["exception_notes"] = "\n" + "\n".join(exc_notes) if frames: |
