Use django-sites for the absolute_url template tag - this actually reduces the number of queries for whatever reason

This commit is contained in:
Danielle McLean 2018-04-20 10:39:52 +10:00
parent 3142c6073c
commit d3c79a4cc3
Signed by untrusted user: 00dani
GPG key ID: 8EB789DDF3ABD240

View file

@ -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)