聪明文档网

聪明文档网

最新最全的文档下载
当前位置: 首页> [IT专家]如何在Jinja中实现djangolike标签

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

时间:2019-05-08 08:19:52    下载该word文档
本文由我司收集整编,推荐下载,如有疑问,请与我司联系如何在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,
  • 29.8

    ¥45 每天只需1.0元
    1个月 推荐
  • 9.9

    ¥15
    1天
  • 59.8

    ¥90
    3个月

选择支付方式

  • 微信付款
郑重提醒:支付后,系统自动为您完成注册

请使用微信扫码支付(元)

订单号:
支付后,系统自动为您完成注册
遇到问题请联系 在线客服

常用手机号:
用于找回密码
图片验证码:
看不清?点击更换
短信验证码:
新密码:
 
绑定后可用手机号登录
请不要关闭本页面,支付完成后请点击【支付完成】按钮
遇到问题请联系 在线客服