My custom templatetag is not working


I need to display the current date in Shamsi calendar in multiple templates so I think of a template tag. Looking at the Django documentation I write this in the inside templatetags folder of my app:

from datetime import datetime

from django import template

from jdatetime import datetime as jdatetime

register = template.Library()

def shamsi_date():
    This template tag returns the current date in Shamsi format.
    now =
    shamsi_date = jdatetime.fromgregorian(now.year, now.month,
    return shamsi_date.strftime('%Y/%m/%d')

And in my template:

{% load shamsi_tags %}
<div>{{ shamsi_date }}</div>

And the output is empty. I check page’s source and I see <div></div> only.

What I’m missing?

Hi, the correct syntax to use tag is {% shamsi_date %}. In your example, you try to render a context variable called shamsi_date, but the context does not contain such variable, hence the empty result