[Answer]-Merge fields in user created email templates in django

1๐Ÿ‘

โœ…

A better solution would be to use the django template system. Have the user enter the message in django template format like:
Dear {{contactname}},
This is your booking confirmation for your vacation from {{startdate}} to {{enddate}} for a total of {{numdays}} days.
Please click {{cancellink}} to cancel your booking.

And then use get_template_from_string from django.template.loader and get a template instance. Than you can render the template by doing template.render(context), Where context is a Context instance found in django.template.context.
You can read more about django template api in https://docs.djangoproject.com/en/1.6/ref/templates/api/ Should be simple from here.

Leave a comment