I am trying to write a Flask API which takes the selected checkboxes from a webpage and puts them into a list to be inputted into some backend python scripts that I have written. The website is being created by a different company. I have watched/read multiple Flask introductions and even written a piece of code which creates a list of checkbox inputs (see below). However the below code is only being run on a development server and I need to be able to integrate this api into an existing website and for it to be called on the click of a button. I tried to look for resources on the web on how to do this but have had no luck. I am very new to Flask and fairly new to python so any help would be appreciated.
from flask import Flask, jsonify, render_template, request
app = Flask(__name__)
@app.route('/tickboxes', methods = ['GET', 'POST'])
def tick_boxes():
if request.method == 'POST':
chosen_categories = request.form.getlist('mycheckbox')
print(chosen_categories)
return chosen_categories
return render_template('checkboxes.html')
if __name__ == '__main__':
app.run()
How can I convert this to use on an existing website?
Aucun commentaire:
Enregistrer un commentaire