Skip to content

Django template tag for using the Python bootstrap-email library

License

Notifications You must be signed in to change notification settings

jhthompson/django-bootstrap-email

Repository files navigation

django-bootstrap-email

Usage

  1. Install
pip install django-bs-email
  1. Add to INSTALLED_APPS
INSTALLED_APPS = [
    # ...
    "django_bootstrap_email",
]
  1. Use the bootstrap_email template tag in your Django template
{% load bootstrap_email %}

{% bootstrap_email %}
<body class="bg-light">
  <div class="container">
    <div class="card my-10">
      <div class="card-body">
          <p>
            {{ message }}
          </p>
      </div>
    </div>
  </div>
</body>
{% end_bootstrap_email %}
  1. Create the email and send it
context = {
    "message": "Hello World!",
}

# you should always include a plain text version of the HTML email
text_content = context["message"]
html_content = render_to_string("path/to/template.html", context)

email_message = EmailMultiAlternatives(
    subject="Greetings",
    body=text_content,
    from_email="[email protected]",
    to=["[email protected]"],
)
email_message.attach_alternative(html_content, "text/html")
email_message.send()

This will produce a complete HTML email that renders consistently across email clients:

Rendered HTML email example

About

Django template tag for using the Python bootstrap-email library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages