Spaces:
Sleeping

Login / Flask.app
Pezh's picture
Create Flask.app
ffebaf9 verified
Raw History Blame Contribute Delete
1.05 kB
from flask import Flask, render_template, request, jsonify
app = Flask(__name__)
# This will hold the items to be displayed as checkboxes.
list_of_items = ['Item 1', 'Item 2', 'Item 3']
# This will hold the items that are checked.
checked_items = []
@app.route('/')
def index():
return render_template('index.html')
@app.route('/multiply', methods=['POST'])
def multiply_by_2():
# Get the number from the input.
number = request.form.get('number')
result = ''
if number:
try:
result = str(int(number) * 2)
except ValueError:
result = 'Invalid input'
# Return the result to the frontend.
return jsonify({'result': result})
@app.route('/check_items', methods=['POST'])
def make_to_checkbox():
global checked_items
# Get the list of checked items from the form.
checked_items = request.form.getlist('items')
# Return something to acknowledge the operation was handled.
return jsonify({'status': 'success'})
if __name__ == '__main__':
app.run(debug=True)