[Django]-How to allow editing of templates for email by admin user in Django?

0πŸ‘

I implemented something similar, here’s what I did:

  1. Create an app, and registered a model to store the email
  2. Set up a management command to process the email
  3. Manage the cron job via django-chronograph

Rendering the email, I used render_to_string, for example

from django.template.loader import render_to_string
from myproject.myemailapp.models import EmailTpl

email_tpl = EmailTpl.objects.get(...#criteria here)
# fetch the rest of your dynamic variables

rendered_tpl = render_to_string(email_tpl.user_entered_tpl, {
    "user": user,
    "cooking_class": cooking_class,
    # ... and so on
})

Alternatively, Django Packages has some packages you might want to look into. Would be great if you post back the route you decided.

πŸ‘€Kenny Shen

0πŸ‘

The plugin django-dbtemplates allows you to store templates in your database, and you can expose the dbtemplate app on your Admin site to edit. You can set your middleware settings such that either the database template or the same template in other locations has priority for loading.

We are using this in a project to manage templates for different products, with the database-stored template for each product linked by ForeignKey.

πŸ‘€JessieinAg

Leave a comment