I use Flask as a web framework, and I am trying to implement the first example from Mike Dewar's book βGetting Started with D3β. I have a Python script called run.py and two templates/ and static/ directories containing index.html and service_status.json , respectively. Unfortunately, my code does not transmit data at all, and it does not create any blatant errors.
This is what I have in run.py :
#!/usr/bin/env python from flask import Flask, render_template, url_for app = Flask(__name__) @app.route('/') def index(): return render_template('index.html') if __name__=="__main__": port = 5000 app.debug = True app.run( port=port )
This is what I have in templates/index.html :
<!DOCTYPE HTML> <HTML> <HEAD> <META CHARSET="utf-8"> <SCRIPT SRC="http://d3js.org/d3.v3.min.js"></SCRIPT> <SCRIPT> function draw(data) { "use strict"; d3.select("body") .append("ul") .selectAll("li") .data(data) .enter() .append("li") .text( function(d){ return d.name + ": " + d.status; } ); } </SCRIPT> <TITLE>MTA Data</TITLE> </HEAD> <BODY> <H1>MTA Availability Data</H1> <SCRIPT> d3.json("{{ url_for( 'static', filename='service_status.json') }}",draw); </SCRIPT> </BODY> </HTML>
I am using Windows 7, Google Chrome and Python 2.7.
source share