After struggling for a week, I am still lost on where to make changes in my code. I need the checkbox to return a boolean value in my Flask application. Below are snippets of the relevant code:
mycode.py
import os, sqlite3
from flask import Flask, flash, request, render_template, send_from_directory, g, session, abort, redirect, url_for
from random import randint
from tkinter.messagebox import *
import os, sqlite3
app = Flask(__name__)
app.config.from_object(__name__)
@app.route('/')
def home():
return render_template('appvolti1.html')
@app.route('/filter')
def viewdb():
global list1
bool_occhiali_checked = request.form.get('occhiali')
if bool_occhiali_checked:
list1 = ["Hello", "World"]
else:
list1 = ["Oh no", "don't work"]
return newpage()
@app.route('/newpage')
def newpage():
return render_template('filter.html', listaimmagini = list1)
if __name__ == '__main__':
app.debug = True
app.run()
appvolti1.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Face Recognition</title>
<style>
@import url(http://fonts.googleapis.com/css?family=Exo:100,200,400);
@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:700,400,300);
body{
background: -webkit-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.65)); /* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.65)); /* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(left, rgba(0,0,0,0), rgba(0,0,0,0.65)); /* For Firefox 3.6 to 15 */
background: rgb(230, 230, 230); /* Standard syntax */
}
.div1{
margin:0 auto;
width:1400px;
display:block;
}
.subdiv1{
display: inline-flex;
display: -webkit-inline-flex;
width: 100%;
}
.subdiv2{
margin: 0 auto;
display: table;
height: 200px!important;
}
.subdiv3{
width:40%;
margin: 0 auto;
display: table;
}
.invia{
display: table-cell;
vertical-align: bottom;
padding: 120px;/*qui gli elementi sono tutti importanti, ti ho lasciato il padding per farlo staccare dalla parte inferiore del contenitore*/
}
.invia input[type=button]{
width: 160px;
height: 35px;
background: #597ef9;
border: 1px silver;
cursor: pointer;
border-radius: 2px;
color: #fff;
font-family: 'Exo', sans-serif;
font-size: 16px;
font-weight: 400;
padding: 6px;
margin-top:100%;
}
.invia input[type=button]:hover{
opacity: 0.8;
}
.invia input[type=button]:active{
opacity: 0.6;
}
.invia input[type=text]:focus{
outline: none;
border: 1px solid rgba(255,255,255,0.9);
}
.invia input[type=password]:focus{
outline: none;
border: 1px solid rgba(255,255,255,0.9);
}
.invia input[type=button]:focus{
outline: none;
}
.checkbox{
margin-left: 50%;
width: 160px;
}
.checkbox div{
color: #5379fa;
font-family: 'Exo', sans-serif;
font-size: 15px;
font-weight:bold;
}
.checkbox div span{
color: #fff !important;
}
</style>
</head>
<body>
<div class="div1">
<div class="subdiv1">
<div class="subdiv2">
<div class="subdiv3" style="width:20%;margin-right:0px;">
<div style="position:relative;">
<div class= "checkbox">
<div><span>Features</span></div>
<div><input type="checkbox" name="glasses">Glasses</div>
</div>
</div>
<div class="invia" style="margin: 0 auto;" >
<input type="button" value="Apply Filters" style="margin-left: -125%;" onclick="location.href = 'http://127.0.0.1:5000/filter';">
</div>
</div>
</div>
</body>
</html>
filter.html
<!DOCTYPE html>
<html>
<head>
<style>
body{
background: rgb(230, 230, 230); /* Standard syntax */
}
</style>
</head>
<body>
{{listaimmagini}}
</body>
</html>