Login

template filter to include protocol and domain in absolute urls

Author:
czer
Posted:
July 4, 2012
Language:
Python
Version:
1.4
Tags:
template filter templatetag template-filter url template-filters get_absolute_url templatefilter absolute
Score:
3 (after 3 ratings)

I created this template filter to be able to use get_absolute_url in an email template.

Save the code into /templatetags/navigation.py

Use like this:

{% load navigation %}

{{ instance.get_absolute_url|siteabsoluteurl:request }}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from django import template
import re

register = template.Library()

@register.filter
def siteabsoluteurl(absoluteurl, request):
	"""
		receives an argument in the form of an absolute url <absoluteurl> 
		Returns the same url with all the necessary path information to be used offsite
	"""
	return request.build_absolute_uri(absoluteurl)

More like this

  1. Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 5 months ago
  2. Crispy Form by sourabhsinha396 6 months ago
  3. ReadOnlySelect by mkoistinen 6 months, 1 week ago
  4. Verify events sent to your webhook endpoints by santos22 7 months, 1 week ago
  5. Django Language Middleware by agusmakmun 7 months, 2 weeks ago

Comments

Please login first before commenting.