Changes between Version 1 and Version 3 of Ticket #28825


Ignore:
Timestamp:
Nov 21, 2017, 9:43:44 PM (7 years ago)
Author:
Andrew
Comment:

It would be best to know, going in, if {extends} is actually *expected* to act like a meta-{%include%} or if the template engine actually combines the two.

I'll work on a better test case or sample project, but it'll probably be a few days. I've not had any cause to ever pull down the source before, and certainly don't know how write proper tests for it, i'm just investigating templates for the first time now.

  • we use the django-templated-email package to wrap doing it, but it ends up in a DjangoTemplates processor.

The Base Email (object_created.email). The base template includes {%include%} directives which seem to be re-evaluated each time, the opposite of extends. My working theory is that somehow the two just get combined on the *first run* and ever-after are the same template somehow (even though I can't find the cache, or figure out who's doing it)

{% extends base_template %}{% load i18n %}
{% block subject_line %}{% blocktrans %}New Something Happened{% endblocktrans %}{% endblock %}
{% block html_content %}
    <h2 style="font-size:15px;">Dear {{ some_person }},</h2>

In the two tests I set the base_template to something different, and also try to reset() all the loaders including the children of the cached.Loader, to no affect.

context_goog = { base_template="email/google_template.email",  some_person="Wonko the Sane" }
context_amzn = { base_template="email/amazon_template.email",  some_person="Wonko the Sane" }

send_templated_email("object_created.email", context_goog)
...
django.template.loader.get_template('email/object_created.email')
  uses engine: <django.template.backends.django.DjangoTemplates object at 0x108573668>
    DjangoTemplates.get_template('email/object_created.email')
      <django.template.engine.Engine object at 0x108d7a2e8>
      .find_template('email/object_created.email') loader=<django.template.loaders.cached.Loader object at 0x10b957ef0>
      .find_template('email/google_template.email') loader=<django.template.loaders.cached.Loader object at 0x10b957ef0>
      .find_template('email/partials/contents-footer.html') loader=<django.template.loaders.cached.Loader object at 0x10b957ef0>


send_templated_email("object_created.email", context_amzn)
...
django.template.loader.get_template('email/object_created.email')
  uses engine: <django.template.backends.django.DjangoTemplates object at 0x108573668>
    DjangoTemplates.get_template('email/object_created.email')
      <django.template.engine.Engine object at 0x108d7a2e8>
      .find_template('email/object_created.email') loader=<django.template.loaders.cached.Loader object at 0x10b957ef0>
      .find_template('email/partials/contents-footer.html') loader=<django.template.loaders.cached.Loader object at 0x10b957ef0>

I hope that printf_trace stuff helps in evaluating what is going on. It might take me a few days to formulate a test case (if I can) or make a new project (if I can't) demonstrating what is going on.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28825 – Description

    v1 v3  
    1313{{{
    1414for template in engines.all():
    15         for loader in template.engine.template_loaders:
    16             loader.reset()
     15    for loader in template.engine.template_loaders:
     16        loader.reset()
     17        for x in loader.loaders:
     18            x.reset()
    1719}}}
Back to Top