草庐IT

timesince

全部标签

python - 将 Python 模块导入 Jinja 模板?

是否可以将Python模块导入Jinja模板以便我可以使用它的功能?例如,我有一个format.py文件,其中包含格式化日期和时间的方法。在Jinja宏中,我可以执行以下操作吗?{%from'dates/format.py'importtimesince%}{%macrotime(mytime)%}{{timesince(mytime)}}{%endmacro%}因为format.py不是模板,所以上面的代码给了我这个错误:UndefinedError:thetemplate'dates/format.py'(importedonline2in'dates/macros.html')d

python - 将 Python 模块导入 Jinja 模板?

是否可以将Python模块导入Jinja模板以便我可以使用它的功能?例如,我有一个format.py文件,其中包含格式化日期和时间的方法。在Jinja宏中,我可以执行以下操作吗?{%from'dates/format.py'importtimesince%}{%macrotime(mytime)%}{{timesince(mytime)}}{%endmacro%}因为format.py不是模板,所以上面的代码给了我这个错误:UndefinedError:thetemplate'dates/format.py'(importedonline2in'dates/macros.html')d