Skip to main content

django-hashtag PyPi license

PyPi status PyPi version PyPi python version PyPi downloads PyPi downloads PyPi downloads

GitHub GitHub release GitHub release

Test codecov.io pre-commit.ci status gitthub.com

Docs

Check Demo Project

  • Check the demo repo on GitHub

Requirements

  • Python 3.9, 3.10, 3.11, 3.12, 3.13, 3.14 supported.
  • Django 3.2, 4.2 and 5.2 supported.

We highly recommend and only officially support the latest patch release of each Python and Django series.

Setup

  1. Install from pip:
pip install django-hashtag
  1. Modify settings.py by adding the app to INSTALLED_APPS:
INSTALLED_APPS = [
    # ...
    "taggit",
    "hashtag",
    # ...
]
  1. Execute Django's command migrate inside your project's root:
python manage.py migrate
Running migrations:
  Applying hashtag.0001_initial... OK
  Applying hashtag.0002_alter_mytag_slug... OK
  Applying hashtag.0003_alter_mytag_last_used... OK

Usage

django-hashtag provides the tag data model plus reusable, consumer-agnostic helpers so every site renders and filters tags the same way without re-implementing the markup or the queryset logic.

Render tags as chips (hashtag_chips)

The hashtag_chips inclusion tag renders a tag collection as accessible chips. It accepts model instances (exposing name/slug/get_absolute_url) or plain strings.

{% load hashtag_tags %}

{# Static, non-linkable chips (e.g. a homepage badge row) #}
{% hashtag_chips tags variant="home" linkable=False %}

{# In-context filter links: builds <filter_url>?<filter_param>=<slug> #}
{% hashtag_chips tags variant="review" filter_url=request.path filter_param="tag" %}

{# Custom href pattern with a {slug} placeholder #}
{% hashtag_chips tags href_pattern="/reviews/?tag={slug}" %}

Arguments:

Argument Default Description
tags — Iterable of tag instances or strings.
variant "" Theme modifier; adds hashtag-chips--<variant> / hashtag-chip--<variant>.
linkable True When False, render <span> chips instead of links.
prefix "#" Text prefix shown before each tag name.
filter_url "" Build an in-context filter link <filter_url>?<filter_param>=<slug>.
filter_param "tag" Query parameter used with filter_url.
href_pattern "" Link template with a {slug} placeholder.
link_class "" Extra CSS class added to each link.
channel "tag" Value for the data-channel attribute (analytics hook).
placement "" Value for the data-placement attribute (analytics hook).
label "" Accessible aria-label for the chip list.

Href resolution order: filter_url -> href_pattern -> get_absolute_url() (when reversible) -> none (renders a <span>).

Style the chips per site via CSS custom properties on the shared classes (hashtag-chip, hashtag-chip--<variant>); a base stylesheet ships at hashtag/static/hashtag/hashtag-chips.css.

Filter a list by tag

hashtag.filtering shares the queryset filter and active-tag lookup used by in-context list views, without referencing any consumer model:

from hashtag.filtering import active_tag_slug, filter_queryset_by_tag

def review_list(request):
    slug = active_tag_slug(request)            # reads ?tag=<slug>
    reviews = filter_queryset_by_tag(Review.objects.all(), slug)
    # ...build your own context/template/pagination...

filter_queryset_by_tag accepts a lookup argument (default "tags__slug") for non-default relation paths; an empty slug returns the queryset unchanged.

Optional canonical tag page (HASHTAG_TAG_URL_NAME)

MyTag.get_absolute_url() is configurable via HASHTAG_TAG_URL_NAME, which defaults to "tagged" for backward compatibility. Set it to "" to disable canonical tag pages:

# Enable canonical per-tag URLs resolved with reverse(name, args=[slug]).
HASHTAG_TAG_URL_NAME = "tagged"

# Or disable canonical tag pages entirely (sites that surface tags only as an
# in-context ?tag= filter); get_absolute_url() then raises NoReverseMatch and
# hashtag_chips falls back to filter_url/href_pattern.
HASHTAG_TAG_URL_NAME = ""

Run Example Project

git clone --depth=50 --branch=django-hashtag https://github.com/DLRSP/example.git DLRSP/example
cd DLRSP/example
python manage.py runserver

Now browser the app @ http://127.0.0.1:8000

Metadata

Release files for django-hashtag 0.4.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-hashtag 0.4.9
File Size Uploaded Provenance Actions
django_hashtag-0.4.9.tar.gz 28.6 kB Without provenance Details for django_hashtag-0.4.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-hashtag 0.4.9
File Interpreter ABI Platform Actions
django_hashtag-0.4.9-py3-none-any.whl Python 3 none any Details for django_hashtag-0.4.9-py3-none-any.whl

Total release size: 50.9 kB

Release files / django_hashtag-0.4.9.tar.gz

Download URL django_hashtag-0.4.9.tar.gz
Size 28.6 kB
Tags Source
SHA-256 checksum
How to use checksums
63cb6252840eca2f6cfd9d7011d882bc605f3dde1813e1199bc466e5d6ac8b9e
BLAKE2b-256 checksum
How to use checksums
af95e8e781e93c1885845840403ffd146acd52456a8938df5b7526e2f95199c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / django_hashtag-0.4.9-py3-none-any.whl

Download URL django_hashtag-0.4.9-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b34ecc7b13e4f9fc72f7f377363b6994040778c17e9d2fd81a1fcab65748baee
BLAKE2b-256 checksum
How to use checksums
4286aa8c11a1762b45714246fe39d003706bbee613aec72b317c36a84d637967
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for django-hashtag 0.4.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page