Skip to content

Commit 5356ae0

Browse files
committed
Add to Readme example
1 parent 796ebac commit 5356ae0

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

README.md

+24-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ INSTALLED_APPS = [
1717
]
1818
```
1919

20-
3. Use the template tag
20+
3. Use the bootstrap_email template tag in your Django template
2121

2222
```html
2323
{% load bootstrap_email %}
@@ -28,7 +28,7 @@ INSTALLED_APPS = [
2828
<div class="card my-10">
2929
<div class="card-body">
3030
<p>
31-
Hello World!
31+
{{ message }}
3232
</p>
3333
</div>
3434
</div>
@@ -37,6 +37,28 @@ INSTALLED_APPS = [
3737
{% end_bootstrap_email %}
3838
```
3939

40+
4. Create the email and send it
41+
42+
```python
43+
context = {
44+
"message": "Hello World!",
45+
}
46+
47+
subject = "Greeting"
48+
# you should always include a plain text version of the HTML email
49+
text_content = render_to_string("path/to/template.txt", context)
50+
html_content = render_to_string("path/to/template.html", context)
51+
52+
email_message = EmailMultiAlternatives(
53+
subject=subject,
54+
body=text_content,
55+
from_email="[email protected]",
56+
57+
)
58+
email_message.attach_alternative(html_content, "text/html")
59+
email_message.send()
60+
```
61+
4062
And a complete HTML email will be output, which should render correctly across email clients:
4163

4264
![Rendered HTML email example](https://raw.githubusercontent.com/jhthompson/django-bootstrap-email/main/example.png)

0 commit comments

Comments
 (0)