Opened 12 years ago
Closed 12 years ago
#19819 closed Bug (fixed)
Django highlights incorrect lines for template errors
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Template system | Version: | 1.4 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
This issue is bugging me for a while now and after searching for existing tickets (and finding none) i've decided to create a ticket for it.
Basically Django highlights the wrong lines when a template error occurs. Sometimes it even highlights a seemingly random line in the parent template (when an error occurs in the template which is included).
I'll attach a screenshot with an example.
Attachments (1)
Change History (5)
by , 12 years ago
Attachment: | Screen Shot 2013-02-13 at 15.36.56.png added |
---|
comment:1 by , 12 years ago
Has patch: | set |
---|
Pullrequest at https://github.com/django/django/pull/721
comment:2 by , 12 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
The patch looks quite good, but it needs a bit of polish.
First, I suggest to redo the PR against master.
You must support Python 2.6+ and 3.2+. Specifically, use the syntax except TemplateSyntaxError as e:
to catch exceptions.
To test an exception, there's assertRaisesRegexp. Since it was renamed in Python 3, you must use this slightly contrived syntax:
from django.utils import six with six.assertRaisesRegex(self, TemplateSyntaxError, ...): # raise exception here
Finally, make sure the code is clean — there a suprious print statement and a stray newline in a docstring.
Thanks!
comment:3 by , 12 years ago
Thanks for the feedback! Here is a new PR against master. Tested it with python 2.6, 2.7 and 3.2:
comment:4 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Example