1

I'm writing a Django 1.4 app that will send HTML email. I'm using Django templates to render the email content, but I'm unsure how to store the templates.

I can store them in an email app (like I would other templates), but it feels silly to use a static file.

I thought about creating an Email model and storing the template code as a TextField, which would work.

I searched for better solutions and saw sendwithus.com on reddit, which is a neat idea...

Is there a Django convention for this sort of thing?

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
bvanvugt
  • 1,212
  • 1
  • 8
  • 15
  • 2
    Why is storing the templates as files "silly"? That's what you do with all other templates, why should it be different just for emails? – Daniel Roseman Jan 13 '13 at 09:25
  • `I thought about creating an Email model and storing the template code as a TextField, which would work.` the only value you would get out of this is you want your end users to edit the templates or create new ones; otherwise the less silly idea of storing them as template files is better. – Burhan Khalid Jan 13 '13 at 10:40
  • 1
    @BurhanKhalid I'd also be able to update and tweak the content myself without requiring a code deploy, which seems beneficial. – bvanvugt Jan 13 '13 at 12:58
  • Unless you are creating something like mailchimp.com - in real life, you don't update email templates often; especially the transactional ones that are sent using such systems. – Burhan Khalid Jan 13 '13 at 13:39
  • Understood, and I agree that's generally true, although it makes me wonder why that's the case. It feels like transactional email is a significant customer touch point that should be updated and optimized. – bvanvugt Jan 13 '13 at 19:11

1 Answers1

1

The general approach is to store email templates either globally in the project template folder or in the template folder of your email app. If you build a reusable app you can provide examples of email templates in your apps template folder, but make it possible to overwrite them via global project template (prioritize project templates before app templates in TEMPLATE_READERS, usually the default in django).

I think you other ideas are overkill for something so simple.

Torsten Engelbrecht
  • 13,318
  • 4
  • 46
  • 48
  • A reusable email app with examples seems like a good idea. But you see no value in making this content editable outside of source? – bvanvugt Jan 13 '13 at 13:06
  • Better to say it should be over-writable/ If you create an email template in your project template folder (following the same directory structure as in your email app) it will simple use this template instead the examples you provided. – Torsten Engelbrecht Jan 13 '13 at 14:13
  • 1
    Ah, gotcha. I'm accepting this answer as a good, Django-specific approach to the original question. But I'm not necessarily convinced that transactional email content should be hardcoded - see comments on question. – bvanvugt Jan 13 '13 at 19:18