我想多次重用以下代码:
body.html文件
<div class="container-fluid">
<div class="row">
<div class="col-md-2 text-dark">
...
<p>Download: <a href="{{ link }}" class="link-secondary">link</a></p>
</div>
<div class="col-md-10">
<iframe src="{{ link }}" style="min-height:88vh;width:100%"></iframe>
</div>
</div>
</div>
在sfa.htmlbody.html并传递以下参数:"{{url_for('static', filename='pdf/Lorem-Ipsum.pdf')}}"
sfa.html
<!DOCTYPE html>
<html>
<head>
{% include 'header.html'%} //works fine
</head>
<body>
{% include 'nav.html'%} //works fine
{% include 'body.html' with 'link' : "{{url_for('static', filename='pdf/Lorem-Ipsum.pdf')}}" %} //here is the problem
</body>
</html>
我在浏览器中得到以下错误:jinja2.exceptions.TemplateSyntaxError: expected token 'end of statement block', got 'with'
我的代码有什么问题?
根据你的情况,我认为你必须这样做:
{% with link="{{url_for('static', filename='pdf/Lorem-Ipsum.pdf')}}" %}
{% include "body.html" %}
{% endwith %}
文档关于这个的其他线程