Django

Code

Ticket #3948 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

improve template parse error to show incorrect token

Reported by: Philippe Raoult Assigned to: adrian
Milestone: Component: Template system
Version: 0.96 Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description (Last modified by ubernostrum)

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

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

Attachments

template_readable_message_v1.diff (0.6 kB) - added by philippe.raoult@gmail.com on 04/10/07 09:42:48.

Change History

04/06/07 17:58:12 changed by philippe.raoult@gmail.com

  • needs_better_patch changed.
  • version changed from 0.95 to 0.96.
  • needs_tests changed.
  • needs_docs changed.

The behavior in 0.96 is exactly the same.

04/06/07 22:57:22 changed by ubernostrum

  • description changed.

(fixing code in description)

04/10/07 09:42:48 changed by philippe.raoult@gmail.com

  • attachment template_readable_message_v1.diff added.

04/10/07 09:45:33 changed by philippe.raoult@gmail.com

  • has_patch set to 1.

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

04/21/07 08:02:00 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch set to 1.
  • stage changed from Unreviewed to Ready for checkin.

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

04/21/07 08:02:38 changed by Simon G. <dev@simon.net.nz>

  • summary changed from template parse parse error isn't readable to improve template parse error to show incorrect token.

04/25/07 02:04:20 changed by mtredinnick

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.

04/25/07 02:05:31 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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


Add/Change #3948 (improve template parse error to show incorrect token)




Change Properties
Action