O
O
Offereight2020-12-22 11:34:45
Django
Offereight, 2020-12-22 11:34:45

How to override the activation_email template in Django?

Good day.
I am developing a website backend using Django and GraphQl (Graphene).

There was a difficulty with using a custom email template that should be sent when registering a new user (activation_email).

Below is the schema code:

import graphene

from graphene_django.types import DjangoObjectType, ObjectType
from graphql_auth.schema import UserQuery, MeQuery
from graphql_auth import mutations
...
from favorite.schema import FavoriteQuery, FavoriteMutation

class AuthMutation(graphene.ObjectType):
    register = mutations.Register.Field()
    verify_account = mutations.VerifyAccount.Field()
    resend_activation_email = mutations.ResendActivationEmail.Field()
    send_password_reset_email = mutations.SendPasswordResetEmail.Field()
    password_reset = mutations.PasswordReset.Field()
    password_change = mutations.PasswordChange.Field()
    archive_account = mutations.ArchiveAccount.Field()
    delete_account = mutations.DeleteAccount.Field()
    update_account = mutations.UpdateAccount.Field()
    send_secondary_email_activation = mutations.SendSecondaryEmailActivation.Field()
    verify_secondary_email = mutations.VerifySecondaryEmail.Field()
    swap_emails = mutations.SwapEmails.Field()

    token_auth = mutations.ObtainJSONWebToken.Field()
    verify_token = mutations.VerifyToken.Field()
    refresh_token = mutations.RefreshToken.Field()
    revoke_token = mutations.RevokeToken.Field()
...


Code in settings.py:
...
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, "templates")],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
...


But templates from 'DIRS': [os.path.join(BASE_DIR, "templates")], are not substituted.
templates/activation_email.html
templates/activation_subject.txt

Instead, a standard template with a greeting and an activation link is substituted.

Tell me what am I doing wrong?
And how to override the default template?

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-12-22
@Offereight

this is the standard template for the graphql_auth library
open the library and see where the templates are, it turns out that you need to put your own in templates/email/activation_email.html, etc.
PS Hoyat of course it was necessary to start from the docks https://django-graphql-auth.readthedocs.io/en/late...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question