15π
Iβd recommend sending both a text version and an html version. Look in the models.py of the django-registration for :
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.user.email])
and instead do something like from the docs http://docs.djangoproject.com/en/dev/topics/email/#sending-alternative-content-types
from django.core.mail import EmailMultiAlternatives
subject, from_email, to = 'hello', 'from@example.com', 'to@example.com'
text_content = 'This is an important message.'
html_content = '<p>This is an <strong>important</strong> message.</p>'
msg = EmailMultiAlternatives(subject, text_content, from_email, [to])
msg.attach_alternative(html_content, "text/html")
msg.send()
27π
To avoid patching django-registration, you should extend the RegistrationProfile model with proxy=True:
models.py
class HtmlRegistrationProfile(RegistrationProfile):
class Meta:
proxy = True
def send_activation_email(self, site):
"""Send the activation mail"""
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
ctx_dict = {'activation_key': self.activation_key,
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
'site': site}
subject = render_to_string('registration/activation_email_subject.txt',
ctx_dict)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
message_text = render_to_string('registration/activation_email.txt', ctx_dict)
message_html = render_to_string('registration/activation_email.html', ctx_dict)
msg = EmailMultiAlternatives(subject, message_text, settings.DEFAULT_FROM_EMAIL, [self.user.email])
msg.attach_alternative(message_html, "text/html")
msg.send()
And in your registration backend, just use HtmlRegistrationProfile instead of RegistrationProfile.
- Displaying Django subcategories in category and products in each category json as Json Child
- Django Rest Framework β AssertionError Fix your URL conf, or set the `.lookup_field` attribute on the view correctly
2π
I know this is old and the registration package is no longer maintained. Just in case somebody still wants this.
The additional steps wrt to the answer of @bpierre are:
β subclass the RegistrationView, i.e. your appβs views.py
class MyRegistrationView(RegistrationView):
...
def register(self, request, **cleaned_data):
...
new_user = HtmlRegistrationProfile.objects.create_inactive_user(username, email, password, site)
β in your urls.py change the view to the sub-classed view, i.e.
β List item
url(r'accounts/register/$', MyRegistrationView.as_view(form_class=RegistrationForm), name='registration_register'),'
- Django does django have an automatic timestamp create/update field like cakephp?
- Postgres: values query on json key with django
- Django 'function' object has no attribute 'objects'
- Form is not valid⦠WHY?
0π
This guy have extended the defaultBackend enabling us to add an HTML version of the activation email.
Specifically, the alternate version job is done here
I managed to use the backend part successfully
- How to implement a paginator that doesn't call count(*)
- Cannot get django-debug-toolbar to appear
- Why swagger raises unclear error β Django