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.
Your jinja2 syntax is not correct.
<input type="checkbox" class="form-control" id="IsValid" name="IsValid" {% if items[6]==1 %}checked{% else %}{% endif %}>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With