Code

Opened 7 years ago

Closed 7 years ago

#5243 closed (fixed)

{% load %} does not load template tags inside sub-directories

Reported by: Bjørn Stabell <bjorn@…> Owned by: nobody
Component: Template system Version: master
Severity: Keywords: load
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by adrian)

According to {% load %} you can load templatetags that are in subdirectories, e.g. {% load news.blah %}. This didn't work for me; I kept getting errors.

Applying the below patch seems to work. I don't know why taglib.split('.')[-1]) was done in the first place? It's been like this for as far back as I could trace the revisions in on this Trac. A related ticket might be #372.

Index: django/template/defaulttags.py
===================================================================
--- django/template/defaulttags.py      (revision 8271)
+++ django/template/defaulttags.py      (working copy)
@@ -792,7 +792,7 @@
     for taglib in bits[1:]:
         # add the library to the parser
         try:
-            lib = get_library("django.templatetags.%s" % taglib.split('.')[-1])
+            lib = get_library("django.templatetags.%s" % taglib)
             parser.add_library(lib)
         except InvalidTemplateLibrary, e:
             raise TemplateSyntaxError, "'%s' is not a valid tag library: %s" % (taglib, e)

Attachments (1)

defaulttags.patch (630 bytes) - added by Bjørn Stabell <bjorn@…> 7 years ago.
Patch to make {% load module.submodule %} work

Download all attachments as: .zip

Change History (6)

Changed 7 years ago by Bjørn Stabell <bjorn@…>

Patch to make {% load module.submodule %} work

comment:1 Changed 7 years ago by adrian

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Fixed formatting in description.

comment:2 Changed 7 years ago by Simon G. <dev@…>

  • Has patch set
  • Summary changed from Bug in {% load %} to {% load %} does not load template tags inside sub-directories
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:3 Changed 7 years ago by mtredinnick

  • Resolution set to fixed
  • Status changed from new to closed

(In [6289]) Fixed #5243 -- Allow loading of templatetags from subdirectories (via dotted notation in {% load %}). Thanks, Bj?\195?\184rn Stabell.

comment:4 Changed 7 years ago by lex.forget@…

  • Resolution fixed deleted
  • Status changed from closed to reopened

For me this patch broke the loading in subdirectories

I am using nesh.thumbnail

in the template: {% load nesh.thumbnail %}

in the settings:
{{{INSTALLED_APPS = (

'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.markup',
'django.contrib.flatpages',
'django.contrib.humanize',
'nesh.thumbnail',

)

}}}

comment:5 Changed 7 years ago by brosner

  • Resolution set to fixed
  • Status changed from reopened to closed

This change was a backward incompatible change. Please see http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges#Templatetagloadingrespectsdottednotation for more information. Please take this to django-users or #django on freenode.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.