title: Loading Data Asynchronously in Python/Flask for d3.js
body: <p>I have a python/flask application. In it I have a page which queries the database a lot in order to display the data on the page. However, if I include this logic in the view.py where the @app.route() is, then loading the page takes too long. I'm then displaying this data with d3.</p>
  
  <p>My current setup is that I have a separate route from the view which calculates the data (let's say "/data" is the path). When you go to that path, it returns the data in a json format and is loaded by </p>
  
  <pre><code>d3.json("/data", callback)
  </code></pre>
  
  <p>This works fine. My issue is that there are a lot of different queries I need to complete, and having a different path for each dataset is cluttering up my app and doesn't seem to be following the DRY principle. Is there a better way to do this? I'm also having difficulties passing variables to the javascript that runs the d3 from python.</p>