1

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!

3
  • 2
    why not try the jQuery ? when user clicks the stock A and get the relevent info from server and return json and parse the json to update the chart... Commented May 30, 2016 at 5:40
  • create get and post api calls in your flask application and then retrieve data from server via those api calls using jQuery. Commented May 30, 2016 at 5:43
  • Have you thought about going with a client side JS Framework? ReactJS sounds perfect! Happy to help refactor, if interested... Commented May 30, 2016 at 13:51

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.