Package: django-fullurl
Introductiondjango-fullurladds three new template tags to Django:fullurl,fullstatic, andbuildfullurl.fullurlandfullstaticbehave likeurlandstaticrespectively, but they always return an absolute URL with the scheme and authority/domain parts.For example, take thisurltag:{%url"articles:article"slug="hello"%}In our example, this prints:/articles/helloThis is called by some an absolute URL, because it begins with a forward-slash. However, it is not anabsoluteabsolute URL, because it does not contain the scheme and authority parts.If we replaceurlwithfullurl, it will print this result:http://example.com/articles/helloBehind the scenes, it usesrequest.build_absolute_urito determine the correct scheme and authority/domain parts.In the same way thatfullurlextendsurl,fullstaticextends thestatictemplate tag.buildfullurltakes a relative URL as an argument, and prints an absolute URL with the scheme and authority parts. For example:{%buildfullurlarticle.cover.url%}InstallationRun on the command-line:$ pip install django-fullurlMake sure these two apps are included in yourINSTALLED_APPSsettings:INSTALLED_APPS=['django.contrib.staticfiles','fullurl',# ...]Make suredjango.template.context_processors.requestis included in your context processors.Template tags summary{% fullurl"some-url-name"v1 v2 %}This behaves like theurlDjango template tag (doc), but it returns a full URL instead of a relative one.{% fullstatic "images/hi.jpg" %}This behaves like thestaticDjango template tag (doc), but it returns a full URL instead of a relative one.{% buildfullurl "/foobar" %}This will convert a relative URL into a full URL usingrequest.build_absolute_uri(doc).Example usageOpenGraphOpenGraph URLs need to be absolute, including scheme and authority parts. Here’s how you can usefullurlandfullstaticto help with this:{%loadfullurl%}<metaproperty="og:url"content="{%fullurl"articles:article"article=article%}"><metaproperty="og:image"content="{%fullstatic"cat.jpg"%}">You can convert a URL from relative to absolute usingbuildfullurltag:{%loadfullurl%}<metaproperty="og:url"content="{%buildfullurlarticle.get_absolute_url%}"><metaproperty="og:image"content="{%buildfullurlarticle.image.url%}">Facebook static share linkIf you want to create a Facebook share button using a link, you can use thesharer.phpfeature. The value for theuquery parameter needs to be an absolute URL, encoded using theurlencodefilter, like this:{%loadfullurl%}<ahref="https://www.facebook.com/sharer/sharer.php?u={%filterurlencode%}{%buildfullurlarticle.get_absolute_url%}{%endfilter%}">Share</a>See alsoHere are some alternatives, in alphabetical order:django-absoluteuri(GitHub,Django Packages) provides two template tags:absoluteuriandabsolutize. Unlike this app, it uses the site framework to determine the domain to use, which could be an additional database query. This can be useful in some situations, for instance when creating emails.django-absoluteurl(GitHub,Django Packages) provides a template tagabsoluteurlthat works in a similar fashion asfullurl. It does not seem to work in Python 2, or with newer Django versions, however.django-full-url (GitHub) allows you to get specific parts of the current URL using code like{{ url_parts.domain }}, among other things. It does not provide the same functionality as this app, the naming similarity was unintentional.django-urltags(Django Packages) provides a few template tags, includingabsurl, but it hasn’t been updated since 2012 and it doesn’t seem to work on recent Django versions.