[Answered ]-Custom template tag to get a remaining days in Django

2👍

First, you need to choose what type of template tag you are writing. It is probably easiest to use an assignment tag. You also need to register the template tag so that it’s available in your template:

Either below your function:

def get_remaining_day(user):
    ...
register.assignment_tag('get_remaining_day', get_remaining_day)

or as a decorator:

@register.assignment_tag(name='get_remaining_day')
def get_remaining_day(user):
    ...

Now you can call it from your template as:

{% get_remaining_day as day %}
{{ day }}

Leave a comment