Marcin
Marcin

Reputation: 49816

How do you locate django template errors?

I have a template which does not parse - instead django raises:

TemplateSyntaxError: Could not parse the remainder: '"{%' from '"{%'

Unfortunately, Django does not disclose where the error is. Is there a tool that can disclose the location of syntax errors in Django templates?

Upvotes: 3

Views: 1168

Answers (3)

bmihelac
bmihelac

Reputation: 6323

Interactive debugger in django-extensions runserver_plus command will make it easier to introspect template node content and template source, as well as look into context variables.

Other than that, be sure that templatetag is importable and do not raise an errors.

Unfortunately, I do not any easier way than that.

Upvotes: 2

okm
okm

Reputation: 23871

Good question,you could check error traceback again:

  • The highlighted template line is the start of the node inside which the broken code resides. I call the node the parent node
  • The last but two item in the tracestack is the key to find the error. Check variables inside its Local vars
    • 'nodelist' -- the list of nodes before the error, inside the parent node.
    • 'compiled_result' -- if there is one, is the last complete node (not including TextNode) before the error

For example, template which looks like

{% block foo %}{{ "{% }} 

raises a error tracestack, the 'nodelist' inside the last but two item could be

nodelist      []

Which means the error is around the first child-node of the block foo.

Upvotes: 2

slow_mondays
slow_mondays

Reputation: 871

Don't think it tells you the exact location but Django Debug Toolbar should help here to some extent.

https://github.com/django-debug-toolbar/django-debug-toolbar

a tour http://vimeo.com/6640136

Upvotes: 0

Related Questions