1

Quick question guys,

Just say I have the code below:

        {% for i in c.targetItems %}
        <tr> {% include "transfers/matching/_process_match_format.html" %} </tr>
        {% endfor %}

In the "_process_match_format.html" I am using a custom template tag. I have to load it in this inclusion file rather then it's parent page otherwise it doesn't seem to be available. Does django only load the custom tag once or does it load it on every pass of the loop?

Additionally, is there way to load the tag in the parent page and make it available for any includes?

Ben Kilah
  • 3,445
  • 9
  • 44
  • 56

1 Answers1

0

According to Django docs: "This means that there is no shared state between included templates -- each include is a completely independent rendering process.". Seems it will load tags each time include is called.

There is a way to load tags for all templates, you need to add them to built-in template tags: Load a Django template tag library for all views by default

Community
  • 1
  • 1
demalexx
  • 4,661
  • 1
  • 30
  • 34
  • 1
    my main concern is the memory consumption of including that tag library in every pass of the loop rather then just loading the tag library on the first pass if that makes sense. – Ben Kilah Apr 18 '12 at 01:39
  • I'm not sure if it'll use too much memory, after one `include` has rendered objects should be freed and GC should collect memory at some time. I've looked at sources and it seems `include` is equal to something like `render_to_string`. The main issue would be speed not memory IMHO. – demalexx Apr 18 '12 at 09:40