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 import template
|
||||||
|
from django.contrib.sites.models import Site
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
from ..utils import origin
|
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag
|
||||||
def absolute_url(context, url):
|
@register.filter(is_safe=True)
|
||||||
return urljoin(origin(context.request), url)
|
def absolute_url(url):
|
||||||
|
base = 'https://' + Site.objects.get_current().domain
|
||||||
|
return urljoin(base, url)
|
||||||
|
|
Loading…
Reference in a new issue