Login

template filter to include protocol and domain in absolute urls

Author:
czer
Posted:
July 4, 2012
Language:
Python
Version:
1.4
Tags:
templatefilter absolute url template-filter template-filters get_absolute_url templatetag filter template
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. Absolute URL Templatetag by johnboxall 5 years, 11 months ago
  2. ScriptPrefixMiddleware by shellsage 5 years, 7 months ago
  3. Hyperlink list filter by lifefloatsby 7 years, 3 months ago
  4. quick_url filter by tclineks 6 years, 11 months ago
  5. order_by template filter by marinho 6 years, 11 months ago

Comments

Please login first before commenting.