override the send activation mail in django-registration

390 views Asked by At

I want to override the send_activation_email in django-registration app in order to be able to send mail with html content instead of just text. Note that this function is defined in the models of the RegistrationManager model.

Thanks a lot in advance.

2

There are 2 answers

3
crazyzubr On BEST ANSWER

Use custom model, example:

from registration.models import RegistrationProfile


class CustomRegistrationProfile(RegistrationProfile):
    """
    Custom registration profile
    """

    class Meta:
        proxy = True

    def send_activation_email(self, site):
        """
        Override method for custom send email
        """

Or, such a method override:

from registration.models import RegistrationProfile

def send_activation_email(self, site):
    """
    Override method for custom send email
    """

RegistrationProfile.send_activation_email = send_activation_email
0
user2707389 On

As RegistrationProfile is a class, you can override it just like you would normally. So you can make an app (or just a file) and create a new proxy model, that will use your html email. (https://docs.djangoproject.com/en/dev/topics/db/models/#proxy-models)

When I had to do something similar last time, I changed the activation_email.txt file instead. That was a much quicker solution.

There might be an easier option though.