[英]How to pass a python variable to html in flask without rendering template
[英]How Make A Variable As A Placeholder In A HTML Template In Flask?
So, I was making an HTML template in Flask And Wanted To Put The Form Label As The PlaceHolder Of A TextBox, But when I try to do so, Flask gives an error.
我的代碼:
<div class="input">
{{ form.username(class="txtb", placeholder={{ form.username.label }}) }}
錯誤 Flask 給出:
jinja2.exceptions.TemplateSyntaxError: expected token ':', got '}'
當我嘗試打印 label 通常像
<h4>{{ form.username.label }}</h4>
它工作得很好。
此外,這也很有效。
<div class="input">
{{ form.username(class="txtb", placeholder="Username") }}
我不知道我哪里錯了。
提前致謝!
您可能想要使用標簽的文本,因為您注意到 label 本身就是完整的<label>
元素。
{{ form.username(class="txtb", placeholder=form.username.label.text) }}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.