Source Code: Link
Extending our previous article “Build a simple Django contact form that sends emails” we will now add a template that can handle dynamic data.
To add a template we need to add two simple components:
- render_to_string() function from django.template.loader
- A HMTL template
Lets start with our template
First lets create a file called email.html and add some varibles. We will create these in the next step.
No in our view lets import render_to_string, create some context and pass it into our template.
Go ahead and replace the message variable with our template variable
No when we send a message our email should look like this: