def send_mail(subject, txt_template, to, context=None, html_template=None, fail_silently=True): """ Multipart message helper with template rendering. """ site = Site.objects.get_current() context = context or {} context.update({ 'login_url': "http://%s" % urljoin(site.domain, reverse('admin:index')), 'title': subject, }) txt_body = render_to_string(txt_template, context) message = EmailMultiAlternatives(subject=subject, body=txt_body, to=to) if html_template: body = render_to_string(html_template, context) message.attach_alternative(body, 'text/html') message.send(fail_silently=fail_silently)
def test_urljoin(self): self.assertEqual('a/b/c/', urlutils.urljoin('a', 'b', 'c')) self.assertEqual('a/b/c/', urlutils.urljoin('a', '//b//', 'c')) self.assertEqual('a/', urlutils.urljoin('a', ''))
def get_absolute_url(self): path = self.get_path() return urlutils.urljoin(reverse('pages-root'), path)