从我的评论:
如果您使用扩展而不是包含,则可以这样做。但是由于解析和渲染步骤之间完全分开,因此直到为时已晚,您才能更改父作用域的上下文。同样,Jinja上下文应该是不可变的。
例:
base.html
<html> <head> {% block head %} <title>{% block title %}This is the main template{% endblock %}</title> <script type="text/javascript"> {% block head_js %} $(function () { $("#abc").css("color", "red"); }); {% endblock %} </script> {% endblock head_js %} </head> <body> {% block body %} <h1>{% block body_title %}This is the main template{% endblock body_title %}</h1> {% endblock body %} </body> </html>
some_page.html
{% block title %}This is some page{% endblock title %}{% block head_js %}{{ super() }}try { {{ caller() }} } catch (e) { my.log.error(e.name + ": " + e.message);} // jquery parlance:{% endblock head_js %}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)