[IT专家]如何在Jinja中实现djangolike标签

本文由我司收集整编,推荐下载,如有疑问,请与我司联系如何在Jinja中实现djangolike标签2015/05/16 292 I would like to implement similar functionality to Django template’s custom tags in Jinja. 我想在Jinja中实现Django模板的自定义标记。  In Django templates, to have a server-side function return a string and have it inserted to a template, you can do something as simple as this: 在Django模板中,要让服务器端函数返回一个字符串并将其插入到模板中,您可以做如下简单的事情: from django import templateregister = template.Library()@register.inclusion_tag(‘app/gallery.html’)defget_gallery(active=None): ### do complex server side things, etc. context_dict = { return context_dict Now, calling this is as simple as 现在,调用它就像  {% load app_tags %}{% get_gallery ‘home’ %} This seems clear and simple enough for me. 这对我来说似乎足够清晰和简单。  Now my question: even after reading through all parts of the Jinja2 documentation, I do not see how a similar functionality should be implemented in Jinja. I’ve seen that Jinja supports macros, calls, imports, custom tests, custom filters, but I cannot see anything related to defining custom tags with arbitrary server-side Python code. 现在我的问题是:即使在阅读了Jinja2文档的所有部分之后,我也不知道如何在Jinja中实现类似的功能。我已经看到Jinja支持宏、调用、导入、自定义测试、自定义过滤器,但是我看不到任何与使用任意服务器端Python代码定义自定义标记相关的内容。  The closest I’ve seen is custom filters, but that has a weird syntax when used for tag-like purposes: to call tag(param1, param2), you’d need to write param1|tag(param2). Also,
《[IT专家]如何在Jinja中实现djangolike标签.doc》
将本文的Word文档下载,方便收藏和打印
推荐:
下载文档
热门推荐
相关推荐