What you need is a macro to define a kind of function in your template. See this topic in http://jinja.pocoo.org/docs/dev/templates/{% macro header_img(name) -%} <img src="{{ url_for('static', filename=name) }}">{%- endmacro %}您可以将此宏放在util模板中,并导入每页.You can put this macro in an util template and import it in each page.使用语法:<header>{{ header_img("your_image.jpg") }}</header> 这篇关于Jinja2中url_for()内的标签块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-13 15:21