Hi All,

I'm using the templating system to send emails, but the templates are being autoescaped. Now, I know I can use {% autoescape off %} in my template files, but the logic I use to build the email body is similar to:

  template_name = 'emails/generic.txt'
  if condition1:
    template_name = 'emails/template1.txt'
  elif condition2:
    template_name = 'emails/template2.txt'
  elif condition3:
    template_name = 'emails/template3.txt'
  body = render_to_string(template_name, context_vars)

The reason I'm shying away from using the autoescape tag is that it breaks DRY in my mind, but it also means that there's more places to miss it and it also seems unnecessary as this is for plain text emails.

I've been reading through the code in django/template to try and work out how the auto-escaping is done, but I have to admit defeat, I can't follow it through at the moment.

So my question is, is there an argument which will disable auto-escaping? If not, would there be some merit to adding some functionality that allows this, either as an argument or perhaps to make the auto-escaping only auto-escape if the template filename ends in '.html'?

Regards
Darryl

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to