Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#26164 closed Uncategorized (invalid)

Django 1.9: All template tags are loaded, whether desired or not

Reported by: Tim Baxter Owned by: nobody
Component: Template system Version: 1.9
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In Django 1.9, anything in /app/templatetags/ appears to be loaded, whether they are loaded into a template or not, desired, or even suited to the current environment.

To reproduce:

  1. Start a fresh Django 1.9 project
  2. pip install typogrify
  3. Create a TemplateView URL, and in the template, simply have "Hello world", with no blocks, no template loading, no nothing.

You will see "ImportError raised when trying to load 'typogrify.templatetags.jinja_filters': No module named jinja2"

Because jinja2 was never pip installed, of course. But Django is loading https://github.com/mintchaos/typogrify/blob/master/typogrify/templatetags/jinja_filters.py anyway.

I don't think an unwanted third-party app should be able to control the environment. If this *is* actually desired or necessary, whether it makes sense to me or not, I think some guidance for template tag writers and site owners to mitigate downsides is in order

Reference: https://github.com/mintchaos/typogrify/issues/44

Change History (4)

comment:2 Changed 7 years ago by Tim Graham

Resolution: invalid
Status: newclosed

Yes, this is intentional. See the section "Template tag modules are imported when templates are configured" added in the backwards-incompatible section of the 1.9 release notes in that commit.

comment:3 Changed 7 years ago by Tim Baxter

Respectfully, I think at the very least there's a documentation improvement to be made here. The single sentence "Template tag modules are imported when templates are configured" falls well short of describing the current behavior, which was was surprising to many experienced Django devs on #django IRC.

I understand that it is intentional, and whether or not I agree it's the correct behavior isn't particularly relevant, but I'm trying to at least minimize surprises and unwanted side-effects.

I would also like to propose a TEMPLATEexclude_tags? = () type setting in which one could add filenames that should explicitly be blocked and never loaded, if they are unwanted. I understand that could get a bit messy and convoluted, but I wanted to float the idea.

comment:4 Changed 7 years ago by Tim Graham

Feel free to propose a documentation patch for the release notes.

Regarding the proposed setting, I think it's more convenient for users if third-party apps adapt their code to raise errors lazily if they want the old behavior rather than requiring users of the app to add certain template tag modules to an exclude setting. Feel free to raise the proposal on the DevelopersMailingList if you disagree.

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