From amundsen.craig at gene.com Tue Aug 1 11:13:45 2017 From: amundsen.craig at gene.com (Craig Amundsen) Date: Tue, 1 Aug 2017 08:13:45 -0700 Subject: [Flask] Datatables question Message-ID: Hi - I've googled around a bit and am having trouble figuring out how to pass a value from a flask page back to the view method that produces the json for loading a datatables table. Currently I'm using datatables to display all the entries in a given table with great success: in an html template where I have table with id="test_table": in views.py: @main.route('/_get-test-rows') def get_test_rows(): trows = Test.query.order_by(Test.name) rows = [ [tr.name, tr.x.name, tr.y, tr.z] for tr in trows] return josnify(data = rows) In my above example, I have another table X that tr.x points to. I'd like to have a page that displays information about individual rows in X that has a table showing all rows from Test that have that point to that particular row in X. @main.route('/show-x/') def show_x(id): x = X.query.get_or_404(id) return render_template('x.html', x = x) I know I can just get all the Test rows I need with tr = Test.query.filter_by(x_id = id).order_by(Test.name) pass them to render_template and render the table myself, but I'd prefer to have a jQuery call in the page that gets the rows of Test where x_id = x.id. Sometimes there are many rows of Test that will be shown and I'd like the page to start loading so the User sees that the click did get through and now we're waiting for the values to get loaded. My problem is that I can't figure out how to write the > > in views.py: > > @main.route('/_get-test-rows') > def get_test_rows(): > trows = Test.query.order_by(Test.name) > rows = [ [tr.name, tr.x.name, tr.y, tr.z] for tr in trows] > return josnify(data = rows) > > > In my above example, I have another table X that tr.x points to. I'd like > to have a page that displays information about individual rows in X that > has a table showing all rows from Test that have that point to that > particular row in X. > > @main.route('/show-x/') > def show_x(id): > x = X.query.get_or_404(id) > return render_template('x.html', x = x) > > I know I can just get all the Test rows I need with tr = > Test.query.filter_by(x_id = id).order_by(Test.name) pass them to > render_template and render the table myself, but I'd prefer to have a > jQuery call in the page that gets the rows of Test where x_id = x.id. > Sometimes there are many rows of Test that will be shown and I'd like the > page to start loading so the User sees that the click did get through and > now we're waiting for the values to get loaded. > > My problem is that I can't figure out how to write the