From d3c79a4cc328f2ece7eca40a39175347a83e3700 Mon Sep 17 00:00:00 2001 From: Danielle McLean Date: Fri, 20 Apr 2018 10:39:52 +1000 Subject: [PATCH] Use django-sites for the absolute_url template tag - this actually reduces the number of queries for whatever reason --- lemoncurry/templatetags/absolute_url.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lemoncurry/templatetags/absolute_url.py b/lemoncurry/templatetags/absolute_url.py index f7ad56a..592079b 100644 --- a/lemoncurry/templatetags/absolute_url.py +++ b/lemoncurry/templatetags/absolute_url.py @@ -1,10 +1,12 @@ from django import template +from django.contrib.sites.models import Site from urllib.parse import urljoin -from ..utils import origin register = template.Library() -@register.simple_tag(takes_context=True) -def absolute_url(context, url): - return urljoin(origin(context.request), url) +@register.simple_tag +@register.filter(is_safe=True) +def absolute_url(url): + base = 'https://' + Site.objects.get_current().domain + return urljoin(base, url)