Hello,
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 shamsi_tags.py
inside templatetags
folder of my app:
from datetime import datetime
from django import template
from jdatetime import datetime as jdatetime
register = template.Library()
@register.simple_tag
def shamsi_date():
"""
This template tag returns the current date in Shamsi format.
"""
now = datetime.now()
shamsi_date = jdatetime.fromgregorian(now.year, now.month, now.day)
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?