Here’s the folder structure:
homepage (this is the Django app)
|
|templatetags
| __init__.py
| shamsi_tags.py
The content of shamsi_tags.py
:
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')
The index.html
:
{% load shamsi_tags %}
...
<div>{{ shamsi_date }}</div>
...
And nothing displays. I check the page source and it shows <div></div>
.
The rest of the page is displaying correctly so I guess there’s nothing wrong with the URL or view.
Obviously jdatetime
is installed.
It is Django 5.0.6 on Windows.
I’m sure this is something easy but I can’t figure it out.