django + wyślij e-mail w html z django-Rejestracja
Im using django-registration, wszystko jest w porządku, e-mail z potwierdzeniem został wysłany w zwykłym tekście, ale wiem im stałe i wysyła w html, ale mam problem śmieci... kod html pokazuje:
<a href="http://www.example.com/accounts/activate/46656b86eefc490baf4170134429d83068642139/">http://www. example.com/accounts/activate/46656b86eefc490baf4170134429d83068642139/</a>
I nie muszę pokazywać kodu html jak..
Jakiś pomysł?Thanks
4 answers
Polecam wysłanie zarówno wersji tekstowej, jak i html. Zajrzyj do models.py django-rejestracja dla:
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.user.email])
I zamiast tego zrób coś takiego z docs http://docs.djangoproject.com/en/dev/topics/email/#sending-alternative-content-types
from django.core.mail import EmailMultiAlternatives
subject, from_email, to = 'hello', '[email protected]', '[email protected]'
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()
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-09-12 05:52:05
Aby uniknąć patchowania django-registration, powinieneś rozszerzyć Model RegistrationProfile o 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()
I w backendzie rejestracji, po prostu użyj HtmlRegistrationProfile zamiast RegistrationProfile.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-26 18:32:00
Wiem, że to jest stare i pakiet rejestracyjny nie jest już utrzymywany. Na wypadek, gdyby ktoś nadal tego chciał.
Dodatkowe kroki wrt do odpowiedzi @bpierre to:
- podklasa widoku rejestracji, czyli Twojej aplikacji views.py
class MyRegistrationView(RegistrationView):
...
def register(self, request, **cleaned_data):
...
new_user = HtmlRegistrationProfile.objects.create_inactive_user(username, email, password, site)
- w Twoim urls.py Zmień widok na podklasowany, tzn. - Pozycja listy
url(r'accounts/register/$', MyRegistrationView.as_view(form_class=RegistrationForm), name='registration_register'),'
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-12-08 00:04:24
Ten facet rozszerzył defaultBackend umożliwiając nam dodanie wersji HTML e-maila aktywacyjnego.
W szczególności zadanie wersji alternatywnej jest wykonywane tutaj
Udało mi się z powodzeniem użyć części backend
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-22 15:26:45