Skip to main content

Useful templatetags for Django projects.

Project description

wt-django-templatetags

Pytest codecov

Useful templatetags for Django projects.

Installation

Install from PyPi:

pip install wt-django-templatetags

Install from GitHub:

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.1.tar.gz (10.0 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.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wt_django_templatetags-1.0.1.tar.gz
  • Upload date:
  • Size: 10.0 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.1.tar.gz
Algorithm Hash digest
SHA256 d7ab001d81b4c5a5234a3d0e05218a82478a44e302ae89316f560842ef257d61
MD5 bf594ed249d35c8ba5dac0b9cf773c47
BLAKE2b-256 ad81d1dadb54387e34e3b1560388c6910ecb1c77970d9c34575ce7f5a4e17c4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wt_django_templatetags-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a4431776c0438c7912e43e4eab495efce04b12016ba81e563e36824d69066929
MD5 c8be6ad57c5b7d7fe1da4587f5429636
BLAKE2b-256 d7ec1c9a4f450e69c0d7608118a1f5d1315d3ca7db59e4ed9021738826f07aec

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