Useful templatetags for Django projects.
Project description
wt-django-templatetags
Useful templatetags for Django projects.
Installation
Install from GitHub (not yet available on PyPI):
To install the development branch from GitHub:
pip install "wt-django-templatetags @ git+https://github.com/ian-wt/wt-django-templatetags.git"
Once installed, add wt_templatetags to INSTALLED_APPS in your settings module.
INSTALLED_APPS = [
# other packages
'wt_templatetags',
]
Alternatively, you could register a particular module of templatetags directly in your
TEMPLATES setting.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
...
],
'libraries': {
'pagination_tags': 'wt_templatetags.templatetags.pagination_tags',
}
},
},
]
This is most useful when you're only interested in using a limited set
of modules from the broader project and that's unlikely to change.
For simplicity, I recommend using the INSTALLED_APPS approach rather
than selectively registering modules.
Use
Pagination Tags
To use the pagination_tags templatetags library in your project,
first load the tags with {% load pagination_tags %}.
To use the relative_url tag, you need to pass to the tag a page index.
This could be a number or the string 'last' if the index is in the final
position of the paginated QuerySet. The tag additionally accepts optional
arguments for field_name and urlencode.
Most often, you'll leave the field_name parameter alone since the default
value of 'page' is fairly semantic as it is. However, this value can be
overridden in your views so make sure your views and the field_name
are consistent.
Last, the urlencode parameter is used when a query string may be present.
If your view won't ever handle a query string, then you can leave the default
value of None alone.
Example
{% extends 'base.html' %}
{% load pagination_tags %}
<h1>Hello World!</h1>
<a href="{% relative_url page_obj.next_page_number %}">Next Page</a>
To extend this example further we can supply values to override the defaults:
{% extends 'base.html' %}
{% load pagination_tags %}
<h1>Hello World!</h1>
<a href="{% relative_url page_obj.next_page_number 'page' request.GET.urlencode %}">Next Page</a>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters