Skip to content

Overriding Email Templates


The default email templates are just examples, you probably want to customize it.

Update your settings:

# settings.py
import os
TEMPLATES = [
    {
        #...
        "DIRS": [os.path.join(BASE_DIR, "templates")],
        # ...
    },
]

File and folder sctructure

Create the following folder and files structure:

- project_name/
    - project_name/
    - templates/
        email/
          activation_email.html
          activation_subject.txt
          password_reset_email.html
          password_reset_subject.txt
      db.sqlite3
      manage.py

This is the minimum. Check the email templates settings, you can create custom templates for:

  • account activation
  • resend account activation email
  • password reset email

Email variables

Both subject and email templates receive the following variables:

  • user
  • token → account activation / password reset
  • port
  • site_name → from django sites framework (optional)
  • domain → from django sites framework (optional)
  • protocol
  • path → defined in settings (some frontend path)
  • request
  • timestamp
  • custom variables defined using EMAIL_TEMPLATE_VARIABLES setting → defined in settings

Writing the templates

Write your templates like this:

<!-- activation_email.html -->

<h3>{{ site_name }}</h3>

<p>Hello \{{ user.username }}!</p>

<p>Please activate your account on the link:</p>

<p>{{ protocol }}://{{ domain }}/{{ path }}/{{ token }}</p>

Provide only the html template. It will be converted to text later.