#24813 closed Cleanup/optimization (fixed)
Document that {% include %} suppresses errors when DEBUG=False
| Reported by: | Pratyush Mittal | Owned by: | andrei kulakov |
|---|---|---|---|
| Component: | Documentation | Version: | 1.8 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Ready for checkin | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
It seems that the TemplateDoesNotExist error is not raised in Django 1.8 tests. Adding {% include "MissingTemplate.html" %} in templates will pass the tests without an error, though it will raise an error on manual browsing.
Demo Code: https://github.com/pratyushmittal/DummyProject
I have provided an example testcase above. In the DummyProject, running python manage.py test should pass the tests, while python manage.py runserver and opening 127.0.0.1:8000 should raise a TemplateDoesNotExist error.
Change History (10)
comment:1 by , 10 years ago
comment:2 by , 10 years ago
It seems that include template tag is altogether being skipped in the tests in Django 1.8.
comment:3 by , 10 years ago
| Component: | Testing framework → Documentation |
|---|---|
| Summary: | TemplateDoesNotExist is not raised in tests → Document that {% include %} suppresses errors when DEBUG=False |
| Triage Stage: | Unreviewed → Accepted |
| Type: | Bug → Cleanup/optimization |
Django tests run with DEBUG=False. In this case, template tag exceptions are often suppressed. It might be worth adding a note to the {% include %} documentation that the tag will render as an empty string if rendering the included template raises an exception.
comment:4 by , 10 years ago
In this case, template tag exceptions are often suppressed
Seems that other template engines should have the same behaviour.
comment:5 by , 10 years ago
I'm not sure what you have in mind, but it doesn't make sense to me that we can enforce design decisions of the Django template language onto other templating languages. In particular, the relevant documentation can be found in the custom template tags docs:
render()should generally fail silently, particularly in a production environment. In some cases however, particularly ifcontext.template.engine.debugisTrue, this method may raise an exception to make debugging easier. For example, several core tags raisedjango.template.TemplateSyntaxErrorif they receive the wrong number or type of arguments.
comment:6 by , 10 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:7 by , 10 years ago
| Has patch: | set |
|---|---|
| Patch needs improvement: | set |
PR (with comments for improvement).
comment:8 by , 10 years ago
| Patch needs improvement: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
Checked on built-in django template engine, error is not rising.
Got
TemplateNotFoundon jinja2.Seems to be a bug.