{"id":6592,"library":"django-classy-tags","title":"Django Classy Tags","description":"django-classy-tags is a Python library that provides a class-based approach to writing custom template tags for Django. It aims to make template tag creation easier, shorter, and more fun by offering an extensible argument parser, significantly reducing boilerplate code while remaining fully compatible with the existing Django templating infrastructure. It is currently at version 4.1.0 and appears to have an active release cadence, with recent updates for Django and Python compatibility.","status":"active","version":"4.1.0","language":"en","source_language":"en","source_url":"https://github.com/django-cms/django-classy-tags","tags":["Django","template tags","class-based","templating","utility"],"install":[{"cmd":"pip install django-classy-tags","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core framework dependency. Version 4.1.0 supports Django >=3.2, 4.0, 4.1, 4.2.","package":"Django"},{"reason":"Requires Python >=3.8. Version 4.1.0 supports Python 3.8, 3.9, 3.10, and 3.11.","package":"Python"}],"imports":[{"symbol":"Tag","correct":"from classytags.core import Tag"},{"symbol":"Options","correct":"from classytags.core import Options"},{"symbol":"Argument","correct":"from classytags.arguments import Argument"},{"symbol":"AsTag","correct":"from classytags.helpers import AsTag"},{"symbol":"InclusionTag","correct":"from classytags.helpers import InclusionTag"},{"symbol":"template","correct":"from django import template"}],"quickstart":{"code":"from classytags.core import Tag\nfrom django import template\n\nregister = template.Library()\n\nclass HelloWorldTag(Tag):\n    name = 'hello_world'\n\n    def render_tag(self, context):\n        return 'Hello, classy world!'\n\nregister.tag(HelloWorldTag)\n\n# In your Django template (.html file):\n# {% load my_app_tags %}\n# {% hello_world %}\n# Output: Hello, classy world!","lang":"python","description":"To create a simple tag, subclass `classytags.core.Tag` and implement the `render_tag` method, which receives the Django context and any defined tag arguments. Finally, register your tag class with a `django.template.Library` instance."},"warnings":[{"fix":"Ensure your project runs on Python >=3.8. For version 4.1.0, Python >=3.8 is required, with optimal support for Python 3.11.","message":"Support for older Python versions was dropped in major releases. Version 3.0.0 dropped Python 3.5 and 3.6. Version 4.0.0 dropped Python 3.7, while adding support for Python 3.11.","severity":"breaking","affected_versions":">=3.0.0, >=4.0.0"},{"fix":"Upgrade Django to a compatible version. For django-classy-tags 4.1.0, Django >=3.2 and up to 4.2 are supported.","message":"Support for older Django versions was removed in major releases. Version 2.0.0 dropped Django < 2.2. Version 4.0.0 dropped support for Django < 3.2, and added support for Django 4.1. Version 4.1.0 supports Django 4.2.","severity":"breaking","affected_versions":">=2.0.0, >=4.0.0"},{"fix":"Always use `register = template.Library()` and `register.tag(YourTagClass)` in your `templatetags/*.py` file, and load your custom tags in templates using `{% load your_app_tags %}`.","message":"Unlike some other template tag libraries, django-classy-tags does not automatically register or load your tags. You must explicitly define and register each tag.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `options = Options(Argument('some_arg'), 'as', Argument('varname', required=False, resolve=False))` pattern is followed for `AsTag` subclasses, or similar structures for other arguments.","message":"When subclassing `classytags.helpers.AsTag`, you must define at least one breakpoint in the `Options` class, and the *last* breakpoint must correspond to exactly one argument (typically for the 'as varname' part).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}