diff --git a/OACPL/utils.py b/OACPL/utils.py
new file mode 100644
index 0000000..c721650
--- /dev/null
+++ b/OACPL/utils.py
@@ -0,0 +1,8 @@
+from django.template.loader import render_to_string
+
+from OACPL import settings
+
+
+def url_fix_render_to_string(template, context):
+ temp = render_to_string(template, context)
+ return temp.replace('src="/', 'src="%s/' % settings.BASE_URL).replace('href="/', 'href="%s/' % settings.BASE_URL)
diff --git a/main/views.py b/main/views.py
index 07a9559..f06b872 100644
--- a/main/views.py
+++ b/main/views.py
@@ -6,6 +6,7 @@ from django.db.models import Q
from django.shortcuts import render, redirect
from django.template.loader import render_to_string
+from OACPL.utils import url_fix_render_to_string
from charter_members.models import Attorney
from newsletters.models import Subscriber
from OACPL import settings
@@ -25,7 +26,7 @@ def contact(request):
result = False
if name is not None and email is not None and subject is not None and body is not None:
result = mail.send_mail('OACPL CONTACT: %(subject)s' % locals(), body, settings.EMAIL_HOST_USER, [settings.EMAIL_CONTACT],
- html_message=render_to_string('email.html', {'content': 'Someone has messaged you via the website contact form!
Subject: %(subject)s
From: %(name)s (%(email)s)
%(body)s' % locals(), 'signature': ' ', 'base_url': settings.BASE_URL}))
+ html_message=url_fix_render_to_string('email.html', {'content': 'Someone has messaged you via the website contact form!
Subject: %(subject)s
From: %(name)s (%(email)s)
%(body)s' % locals(), 'signature': ' '}))
return JsonResponse({'success': True if result else False})
diff --git a/newsletters/management/commands/sendnewsletters.py b/newsletters/management/commands/sendnewsletters.py
index 06829c0..19d8f41 100644
--- a/newsletters/management/commands/sendnewsletters.py
+++ b/newsletters/management/commands/sendnewsletters.py
@@ -3,9 +3,9 @@ from django.core import mail
from django.core.management.base import BaseCommand
from django.utils import timezone
from django.utils.html import strip_tags
-from django.template.loader import render_to_string
from OACPL import settings
+from OACPL.utils import url_fix_render_to_string
from newsletters.models import Newsletter, Subscriber
@@ -19,7 +19,7 @@ class Command(BaseCommand):
print('Found %s subscribers' % len(subscribers))
for newsletter in newsletters:
print('Sending newsletter: "%s"' % newsletter.subject)
- mail.send_mail(newsletter.subject, strip_tags(newsletter.body), settings.EMAIL_HOST_USER, subscribers, html_message=render_to_string('email.html', {'content': newsletter.body, 'base_url': settings.BASE_URL}))
+ mail.send_mail(newsletter.subject, strip_tags(newsletter.body), settings.EMAIL_HOST_USER, subscribers, html_message=url_fix_render_to_string('email.html', {'content': newsletter.body}))
newsletter.sent = True
newsletter.save()
print('Complete!')