python - 在 Mako 中捕获 body 内容?

标签 python mako

是否可以从 Mako 模板中获取渲染的正文内容?我的意思是我可以使用 ${self.body()} 显示正文,但是如果我想先对其执行某些操作该怎么办?

最佳答案

显然我正在寻找的是 capture function 。来自文档:

The other way to buffer the output of a def or any Mako callable is by using the built-in capture function. This function performs an operation similar to the above buffering operation except it is specified by the caller.

${" results " + capture(somedef) + " more results "}

或者就我而言:

<%
    body = capture(self.body)
    # etc.
%>

关于python - 在 Mako 中捕获 body 内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7479572/

相关文章:

python - Mako 模板 0.8 如何包含值是变量的文件?

python - 是否有理由劝阻我在我的 Django 应用程序中使用替代模板引擎?

python - 使用 XPath 检索 span 类中的文本

python - 寻找交叉点基于区域的轨迹与线轨迹

python - 我应该关闭在上下文管理器 __exit__() 函数中传递到我的对象的流(类文件对象)吗?

python - 有没有办法在换行符很重要的纯文本文件中使用 Mako 模板?

python - Django 外键 : is it possible to ask for a name instead of an id?

python - Flask-在2条不同的 route 使用相同的变量?

python - 用 mako 格式化

syntax-highlighting - Notepad++ 在任何 <% 的 Mako Templates 标签之后都会丢失高亮的 HTML 标签。如何禁用此行为?