简体   繁体   English

如何在烧瓶中写复选框?

[英]How to write checkbox in flask?

I want to render a template.In the template, I have a checkbox called "IsValid", its value is from database. 我要呈现一个模板。在模板中,我有一个名为“ IsValid”的复选框,其值来自数据库。 I want to read and edit the state of checkbox. 我想阅读和编辑复选框的状态。 After edit the checkbox, I want to store the its value in the database. 编辑复选框后,我要将其值存储在数据库中。 How should I write the checkbox? 我应该如何编写复选框?

<div class="form-group">
    <label for="IsValid" class="control-label col-md-2">IsValid</label>       
<div class="col-md-2">
    <input type="checkbox" class="form-control" id="IsValid" name="IsValid" {{ checked="checked" if items[6]=1 else "" }} " >
</div>
</div>

In the code, items[6] is passed by view function.It's value is from database, it has two values,0 and 1. 在代码中, items [6]由视图函数传递。它的值来自数据库,它有两个值,0和1。

How to modify {{ checked="checked" if items[6]=1 else "" }} ? {{ checked="checked" if items[6]=1 else "" }}如何修改{{ checked="checked" if items[6]=1 else "" }}

Because it is wrong. 因为这是错误的。

Wrong information:jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got '=' 错误信息:jinja2.exceptions.TemplateSyntaxError:预期标记“打印语句结束”,得到了“ =”

I don't know if you can understand because my English is poor. 我不知道你是否能听懂,因为我的英语不好。

Your jinja2 syntax is not correct. 您的jinja2语法不正确。 <input type="checkbox" class="form-control" id="IsValid" name="IsValid" {% if items[6]==1 %}checked{% else %}{% endif %}>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM