Skip to main content

Useful templatetags for Django projects.

Project description

wt-django-templatetags

Pytest codecov

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wt_django_templatetags-1.0.0.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wt_django_templatetags-1.0.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file wt_django_templatetags-1.0.0.tar.gz.

File metadata

  • Download URL: wt_django_templatetags-1.0.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.2

File hashes

Hashes for wt_django_templatetags-1.0.0.tar.gz
Algorithm Hash digest
SHA256 53a60a1fafe9ffcc7a1f1def5d1bfda7fe5c25cd455a6ed14413042bd824477a
MD5 083191923bbc8d9052de79700f595c35
BLAKE2b-256 5c9acc2bd427cec18eb8437e3d0cc7a2c2eab563b7c40f63ddff5a19d8b5dcec

See more details on using hashes here.

File details

Details for the file wt_django_templatetags-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wt_django_templatetags-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c2533044a0a5b412a431d5302441f920a0197f9db21ab56aecfbe5a59941183
MD5 c9ca1d8cf362fa4ef503f8360cf240c0
BLAKE2b-256 6483301379b339c44f547b50ebffd45be1a1bdbbc081d6e7caf377ae6a002b01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page