I'm starting in flask, so i have many questions about it. And one of them is how to create an array based on name of the checkbox input? In other words, python will follow the logic: for each of type "checkbox", which ones were filled?
I have those codes: index.html
{% block content %}
<form method="POST" action="">
<div class="card" style="margin:50px 0">
<div class="card-header"><b>Letters</b></div>
<ul class="list-group list-group-flush">
<li class="list-group-item">A
<label class="switch ">
<input type="checkbox" name="A" class="danger">
<span class="slider round"></span>
</label>
</li>
<li class="list-group-item">B
<label class="switch ">
<input type="checkbox" name="B" class="danger">
<span class="slider round"></span>
</label>
</li>
<li class="list-group-item">C
<label class="switch ">
<input type="checkbox" name="C" class="danger">
<span class="slider round"></span>
</label>
</li>
</ul>
<button type="submit">Go</button>
</div>
</form>
{% endblock content %}
And funcs.py
from flask import Flask, render_template, url_for, redirect, request
app = Flask(__name__)
app.config['SECRET_KEY'] = '0000'
@app.route('/')
def index():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)
When the user has checked boxes named "A" and "C", python creates an array and display the array shortly afterwards when the user submit.
checked = ["A", "C"]