是否可以从 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/