Opened 8 months ago

Last modified 6 weeks ago

#28050 assigned New feature

TemplateSyntaxError should contain template name

Reported by: Petr Dlouhý Owned by: Roger Masse
Component: Template system Version: 1.11
Severity: Normal Keywords: TemplateSyntaxError template
Cc: Roger Masse Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If there is an error in template, Django doesn't report the template name. It could be quite uneasy to find the buggy template in such case.

e.g.: I have got following error:

  File "/home/petr/soubory/programovani/Auto-mat/DPNK/dpnk/env/lib/python3.5/site-packages/django/template/base.py", line 509, in parse
    self.invalid_block_tag(token, command, parse_until)
  File "/home/petr/soubory/programovani/Auto-mat/DPNK/dpnk/env/lib/python3.5/site-packages/django/template/base.py", line 565, in invalid_block_tag
    get_text_list(["'%s'" % p for p in parse_until], 'or'),
django.template.exceptions.TemplateSyntaxError: Invalid block tag on line 127: 'endblock', expected 'empty' or 'endthumbnail'. Did you forget to register or load this tag?

It contains even line number, but I have no idea in which file.

I think, it is not that difficult to include template name in the bug report. In my case I tried to debug the error call. In django.template.base, the invalidb_block_tag is called from parse() where the template name can be obtained from self.origin.template_name.

Change History (10)

comment:1 Changed 8 months ago by kapil garg

Triage Stage: UnreviewedAccepted

comment:2 Changed 8 months ago by kapil garg

Owner: changed from nobody to kapil garg
Status: newassigned

comment:3 Changed 8 months ago by kapil garg

Has patch: set
Last edited 6 months ago by Tim Graham (previous) (diff)

comment:4 Changed 6 months ago by Tim Graham

Patch needs improvement: set

I'm not particularly pleased with the current patch which causes the template name to be displayed redundantly several times in the debug view. Hopefully we could avoid that.

comment:5 Changed 3 months ago by Roger Masse

Owner: changed from kapil garg to Roger Masse

My plan is to improve the patch as described in the pull request with the suggestion by timgraham:

There might be a possibility for the debug view to modify TemplateDoesNotExist's message so the redundant template names aren't added. In any case, a test is required.

comment:6 Changed 3 months ago by Roger Masse

Patch needs improvement: unset

comment:7 Changed 3 months ago by Roger Masse

Has patch: unset

comment:8 Changed 3 months ago by Roger Masse

Has patch: set
Last edited 3 months ago by Roger Masse (previous) (diff)

comment:9 Changed 3 months ago by Roger Masse

Cc: Roger Masse added

comment:10 Changed 6 weeks ago by Tim Graham

#28698 is a duplicate with an alternate approach.

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