I have a dashboard, where a user can select from a list of available movie genres. They can also select a movie runtime. When looking at the console, it looks like the values are being “posted” to my application. However, the “checkboxes” are being sent where the keys are the individual names, and the value is “on”. What I’d like to do is have them post where the values are the names. From there I’d like to use the movie genres, as well as the runtime as a bind parameter for a separate PL/SQL procedure (not shown here/not accomplished yet). However, I cannot find a solution anywhere on here. I think part of the issue is that I am using Jinja templating to dynamically pass in those values to the index.html page.
Anybody on here have any suggestions?
hello.py
from flask import Flask, redirect, render_template, url_for, request, Response
from flask_bootstrap import Bootstrap
import requests
import jinja2
from flask_wtf import FlaskForm
app = Flask(__name__)
@app.route('/')
def index():
response = requests.get('https://[my_ORDS_endpoint].adb.us-ashburn-1.oraclecloudapps.com/ords/admin/mymovies/genres')
# print(response.text)
genrelist = []
for i in response.json()["items"]:
genre = i['genre']
genrelist.append(genre)
return render_template('index.html', genrelist=genrelist)
@app.route('/handle_data', methods=['GET', 'POST'])
def handle_data():
if request.method == 'POST':
data = request.form.to_dict('name')
print(data)
return redirect("/")
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)
index.html
<body class="p-3 m-0 border-0 bd-example m-0 border-0 bd-example-row">
<div class="container text-center">
<div class="row row-cols-3">
<div class="col">
<form action="{{ url_for('handle_data')}}" method="POST">
{% for genre in genrelist %}
<input type="checkbox" class="btn-check" id="{{ genre }}" name = "{{ genre }}" autocomplete="off">
<label class="btn btn-primary" for="{{ genre }}">"{{ genre }}"</label>
{% endfor %}
<label for="customRange3" class="form-label">Example range</label>
<input type="range" class="form-range" min="1" max="4" step="0.5" id="customRange3" name="customRange3">
<input type="submit">
</form>
</div>
<div class="col">Column</div>
</div>
</div>
<div class="container">
</div>
</body>
I have been working on this for about three days straight. I have looked through the Jinja2 docs, Flask. I’ve watched hours of youtube videos trying to find this exact use case. I’ve looked into O-Reilly books as well. I haven’t been able to find anything that explains or illustrates this issue.