A flag has a built-in object called a query. The request has a multitasking argument args.
You can use request.args.get('key') to get the value of the query string.
from flask import request @app.route('/example') def example(): # here we want to get the value of the key (ie ?key=value) value = request.args.get('key')
Of course, this requires a request for receipt (if you use a post, use request.form ). On the javascript side, you can request a get using pure javascript or jquery. I am going to use jquery in my example.
$.get( url="example", data={key:value}, success=function(data) { alert('page content: ' + data); } );
This is how you transfer data from the client to the flask. The functional part of jquery code is how you pass data from a flask to jquery. Say, for example, you have a view called / example, and from the jquery side you pass a pair of values ββfor the key "list_name": "example_name"
from flask import jsonify def array(list): string = "" for x in list: string+= x return string @app.route("/example") def example(): list_name = request.args.get("list_name") list = get_list(list_name)
and in the success function in jquery you say
success=function(data) { parsed_data = JSON.parse(data) alert('page content: ' + parsed_data); }
Note that the checkbox does not allow top-level lists in the json response for security reasons.
source share