The template tag `fullurl` acts just like `url`, but it always prints absolute URLs with scheme and domain
Project description
Introduction
django-fullurl adds two new template tags: fullurl and staticurl. They behave like url and staticurl respectively, but they always return an absolute URL with the scheme and authority/domain parts.
For example, take this url tag:
{% url "articles:article" slug="hello" %}
In our example, this prints:
/articles/hello
This is called by some an absolute URL, because it begins with a forward-slash. However, it is not an absolute absolute URL, because it does not contain the scheme and authority parts.
If we replace url with fullurl, it will print this result:
http://example.com/articles/hello
Behind the scenes, it uses request.build_absolute_uri to determine the correct scheme and authority/domain parts.
In the same way that fullurl behaves like url, fullstatic behaves like the static template tag.
Installation
Run on the command-line:
$ pip install django-fullurl
Make sure these two apps are included in your INSTALLED_APPS settings:
INSTALLED_APPS = [ 'django.contrib.staticfiles', 'fullurl', # ... ]
Make sure django.template.context_processors.request is included in your context processors.
Example usage
OpenGraph URLs need to be absolute, including scheme and authority parts. Here’s how you can use fullurl and fullstatic to help with this:
{% load fullurl %} <meta property="og:url" content="{% fullurl "articles:article" article=article %}"> <meta property="og:image" content="{% fullstatic "cat.jpg" %}">
Changelog
0.2 (2017-03-02)
Add support for Django 1.8 and Django 1.9, in addition to Django 1.10.
Add support for Python 2.7, Python 3.2, 3.3, 3.4 and 3.5, in addition to Python 3.6.
0.1 (2017-03-01)
First release on PyPI.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for django_fullurl-0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce7ae1d13a7e6ad16be382568959708413c4e8c3cdcd76c39bd3d2caef01c466 |
|
MD5 | 125ad1783cb3e57a4da36f905a0d7d83 |
|
BLAKE2b-256 | 5327897718e904599ba8e4809a9ecdd51cc960ff10a4065a3e3e148ad41019cb |