Opened 12 years ago

Closed 12 years ago

#3948 closed (fixed)

improve template parse error to show incorrect token

Reported by: Philippe Raoult Owned by: Adrian Holovaty
Component: Template system Version: 0.96
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by James Bennett)

I'm fooling around django trying to do some rapid prototyping and I naively typed the following in my template:
{{ object.other_related_class_set.count() }}

This error is valid in the sense that my template code is bogus, but I had to test line by line to figure out what was wrong. It would be great if the exeption contained the offending line or token!

Traceback included, ask for more details if you need but this is pretty easy to reproduce I think

Traceback (most recent call last):
File "/var/lib/python-support/python2.4/django/core/handlers/" in get_response
  74. response = callback(request, *callback_args, **callback_kwargs)
File "/home/philippe/dev/LLR/djprototype/../djprototype/marques/" in marque_detail
  13. mytemplate = loader.get_template("marques/marque_detail.html")
File "/var/lib/python-support/python2.4/django/template/" in get_template
  79. return get_template_from_string(*find_template_source(template_name))
File "/var/lib/python-support/python2.4/django/template/" in get_template_from_string
  86. return Template(source, origin)
File "/var/lib/python-support/python2.4/django/template/" in __init__
  146. self.nodelist = compile_string(template_string, origin)
File "/var/lib/python-support/python2.4/django/template/" in compile_string
  161. return parser.parse()
File "/var/lib/python-support/python2.4/django/template/" in parse
  239. filter_expression = self.compile_filter(token.contents)
File "/var/lib/python-support/python2.4/django/template/" in compile_filter
  323. return FilterExpression(token, self)
File "/var/lib/python-support/python2.4/django/template/" in __init__
  543. raise TemplateSyntaxError, "Could not parse the remainder: %s" % token[upto:]

  TemplateSyntaxError at /marques/details/1/
  Could not parse the remainder: ()

Attachments (1)

template_readable_message_v1.diff (632 bytes) - added by philippe.raoult@… 12 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 12 years ago by philippe.raoult@…

Version: 0.950.96

The behavior in 0.96 is exactly the same.

comment:2 Changed 12 years ago by James Bennett

Description: modified (diff)

(fixing code in description)

Changed 12 years ago by philippe.raoult@…

comment:3 Changed 12 years ago by philippe.raoult@…

Has patch: set

The attached patch at least prints the full offending token. It's a bit better but I haven't figured out where to find the filename:line number to add it!

ps: patch is against newforms-admin branch but should apply cleanly to 0.96

comment:4 Changed 12 years ago by Simon G. <dev@…>

Patch needs improvement: set
Triage Stage: UnreviewedReady for checkin

Tentatively marked as ready to go, unless someone can improve the patch as per comment 3.

comment:5 Changed 12 years ago by Simon G. <dev@…>

Summary: template parse parse error isn't readableimprove template parse error to show incorrect token

comment:6 Changed 12 years ago by Malcolm Tredinnick

I messed around with this once before and, I agree, it requires more than just a couple of changes to get the exact location inside classes like FilterExpression. It would basically require extracting that information from Template.parse() and passing it into each node type that wanted it.

comment:7 Changed 12 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [5067]) Fixed #3948 -- Added some extra relevant information to FilterExpression
parse-related error message. Thanks, philippe.raoult@….

Note: See TracTickets for help on using tickets.
Back to Top