简体   繁体   English

如何在龙卷风模板中实现自定义标签

[英]How to implement a custom tag in tornado templating

I have a situation where i need to do some logics inside the template. 我有一种情况,我需要在模板内执行一些逻辑。 I found that i can pass the function with the controller but my problem needs exact solutions like below. 我发现我可以通过控制器传递函数,但是我的问题需要如下所示的精确解决方案。 Anyone there to help me sort it.? 有人可以帮我排序吗?

eg: index.html 例如:index.html

{% code %}
  def sum(a, b):
      return a + b
{% end %}
<body>
   <b>Sum:</b> {{ sum(10, 20)  }}
</body>

Tornado's template system does not support defining multi-line functions inside the template. 龙卷风的模板系统不支持在模板内部定义多行功能。 In simple cases you can use {% set f = lambda... %} but all other functions must come from outside the template (either passed in via the namespace or imported within the template with the {% import %} directive). 在简单的情况下,可以使用{% set f = lambda... %}但所有其他函数必须来自模板外部(通过命名空间传递或通过{% import %}指令{% import %}模板)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM