24👍
✅
First of all, you haven’t defined register
:
To be a valid tag library, the module must contain a module-level
variable named register that is a template.Library instance, in which
all the tags and filters are registered.
Also, I usually decorate the function with register.filter
:
from django import template
register = template.Library()
@register.filter
def intcomma(value):
return value + 1
2👍
import register from django.template.defaulttags
from django.template.defaulttags import register
views.py
from django.template.defaulttags import register
@register.filter
def intcomma(value):
return value + 1
..........................other code.................................
list.html
{% extends "base.html" %}
{% block content %}
<ul>
<li><h1>{{ 2.568|intcomma|floatformat:"0" }}</h1></li>
</ul>
{% endblock content %}
Output like this:-
👤lava
- Multiple user type sign up with django-allauth
- How to display "x days ago" type time using Humanize in Django template?
- Django custom for complex Func (sql function)
- Django CSRF cookie not set correctly
- Django post checkbox data
Source:stackexchange.com