Skip to main content

A simple Django app to create and send editable emails.

Project description

Django HTML Email Templates

A Django app for allowing users to create html emails using Django template variables passed in to the context.

Installation

Use the package manager pip to install django-html-emailtemplates.

pip install django-html-emailtemplates

Add the package to your INSTALLED_APPS

INSTALLED_APPS = [
    ...
    'emailtemplates',
    ...
]

Usage

# models.py
from emailtemplates.fields import EmailTemplateField
class Settings(models.Model):
    contact_form_reply = EmailTemplateField(
        models.SET_NULL,
        null=True,
        email_context="""
        You can use the following variables in the template:
        {{ name }}
        {{ subject_matter }}
        {% for item in items %}
            Possible values are:
            {{ item.title }}
            {{ item.cost }}
            {{ item.description }}
        {% endfor %}
        """
    )

# views.py
from emailtemplates.utils import send_email_template
from emailtemplates.models import EmailTemplate
from .models import Settings

# view definition
def form_valid(self, form):
    enquiry = form.save()
    # send reply email to website user
    send_email_template(
        Settings.objects.first().contact_form_reply,
        [enquiry.email],
        {
            'name': enquiry.name,
            'subject_matter': enquiry.subject,
            'items': [
                {
                    'title': 'Product',
                    'cost': '£20.00',
                    'description': 'Product description...'
                }
            ]
        }
    )
    # send notification to website owner
    send_email_template(
        EmailTemplate(
            subject='Enquiry from example.com',
            content='''<div>
                <p>There was an enquiry on your website, the details are below:</p>
                <table>
                    <tbody>
                        <tr>
                            <td>Name:</td>
                            <td>{{ enquiry.name }}</td>
                        </tr>
                    </tbody>
                </table>
            </div>'''
        ),
        ['contact@example.com'],
        {
            'enquiry': enquiry
        }
    )

alt text

Features to add

  • Add custom ForeignKey field to display the context that can be used
  • Add base email header/footer
  • Add plugins for images/documents
  • Add better html field
  • Add support for Wagtail StreamField

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-html-emailtemplates-0.0.2.tar.gz (8.7 kB view details)

Uploaded Source

File details

Details for the file django-html-emailtemplates-0.0.2.tar.gz.

File metadata

  • Download URL: django-html-emailtemplates-0.0.2.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for django-html-emailtemplates-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2518590da432a657c10061de66e8ba8cbf154d0bdf08fe2320a0b8582b3fb419
MD5 aac02cb72e883fe301af96a1fc2b9c13
BLAKE2b-256 82afcdd755e742e2e6a17ea0571529c52faa87253f2f5085b7a902e0bf66d69d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page