Reputation: 1153
I am trying to use python flask framework to build a webpage. This webpage is a dashboard, which has two divs. The first div is a table, each row of which is the info for a certain stock. The second div is a chart which shows the price curve for one of the stocks in the first table.
I would like to refresh the second chart based on the selection from the first table. For example, if I click on the name of stock A in the first table, the price curve for A is then showed in the second chart.
One way to implement this, is to link each stock name to a different url, and have a html file associated with each url address. A series of render_template functions have to be defined in the view.py script.
I wonder if there's a more generic way to implement this. Maybe one function definition and one html template would be enough for all stocks in the table?
thanks!
Upvotes: 1
Views: 544
Reputation:
You can generate URL in flask using url_for(). So maybe your template to generate charts can use url_for('/stock', stock_name='GOOG'). Which will embed the route /stock/GOOG into a link to show a chart for GOOG.
Then you can use a nested template to show the chart div when the above route is called.
Here is link to the relevant documentation: http://flask.pocoo.org/docs/0.11/quickstart/#url-building http://flask.pocoo.org/docs/0.11/patterns/templateinheritance/
Upvotes: 1