Print Format Jinja Issue

Hello,
In my project I need to convert from Gregorian to Arabic Hijri date, I need to print the current printing date in Hijri
This is my code, I use umalqurra library for that:

from umalqurra.hijri_date import HijriDate
import datetime

def hijry():
	datee = datetime.datetime.strptime(frappe.utils.today(), "%Y-%m-%d")
	um = HijriDate(datee.year,datee.month,datee.day,gr=True)
	print int(um.year), um.month_name , int(um.day)

I change this code to jinja like follow:

{% set datee = datetime.datetime.strptime(frappe.utils.today(), "%Y-%m-%d") %}
{% set um = HijriDate(datee.year,datee.month,datee.day,gr=True) %}        
{{ int(um.day) }}

When I check print format, it shows this error

UndefinedError: ‘datetime’ is undefined

I try to include it in jinja like this :

{% import datetime %}
{% from umalqurra.hijri_date import HijriDate %}

But it still the same!
Any solution
thanks

1 Like

We only allow limited methods in Jinja for security reasons.

See frappe/jinja.py at develop · frappe/frappe · GitHub

1 Like

I solve it by adding my function in the utils with importing code
and then call it in jinja using
{{ frappe.get_hijry() }}

1 Like

it will get overwritten next bench update …

1 Like

try to create ur method in ur custom app dont update in frappe codebase it will be overwritten when u do bench update

1 Like

@hereabdulla @JoEz
thanks , we chose stable frappe to be fixed in project

Hello @OmarJaber
Can you explain more how you do it, and share your code please.

This is my code