I am trying to set a checkbox if it is checked in a past template. In other way if the user check the checkbox and click on submit button, he should be able to see what options he has checked. My code is like this:
if request.GET.get('submit', '').strip():
checkbox = request.GET.get('box1')
return template('my_template.j2', box1 = checkbox)
How can I do it?
In your template file you can add the following:
<input type="checkbox" name="box1" value="box1" {{'checked="checked"' if box1 else ""}}/>
You can use the python objects passed into the template inside the curly braces, you can find more information in the documentation for inline expressions.
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