João Pedro Francese avatar João Pedro Francese committed 817f448

Adding {% absurl %} templatetag.

Comments (0)

Files changed (2)

Add a comment to this file


Empty file added.


+# -*- coding: utf-8 -*-
+# Downloaded on 2011-07-03 from
+# Edited with junckritter's change from
+from django.contrib.sites.models import Site
+from django.template import Library
+from django.template.defaulttags import URLNode, url
+import urlparse
+register = Library()
+class AbsoluteURLNode(URLNode):
+    def render(self, context):
+        path = super(AbsoluteURLNode, self).render(context)
+        # domain = settings.ABSOLUTE_BASE_URL
+        domain = "http://%s" % Site.objects.get_current().domain
+        if self.asvar:
+            context[self.asvar] = urlparse.urljoin(domain, context[self.asvar])
+            return ''
+        else:
+            return urlparse.urljoin(domain, path)
+def absurl(parser, token, node_cls=AbsoluteURLNode):
+    """Just like {% url %} but ads the domain of the current site."""
+    node_instance = url(parser, token)
+    return node_cls(view_name=node_instance.view_name,
+        args=node_instance.args,
+        kwargs=node_instance.kwargs,
+        asvar=node_instance.asvar)
+absurl = register.tag(absurl)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.