Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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.

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

Because it is wrong.

Wrong information:jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got '='

I don't know if you can understand because my English is poor.

like image 350
qiaocc Avatar asked Jan 19 '17 09:01

qiaocc


1 Answers

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

like image 66
Alexander Sharagov Avatar answered Sep 23 '22 06:09

Alexander Sharagov