Use django-sites for the absolute_url template tag - this actually reduces the number of queries for whatever reason
This commit is contained in:
parent
3142c6073c
commit
d3c79a4cc3
1 changed files with 6 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue