【发布时间】:2015-02-02 00:15:44
【问题描述】:
我有一个 Flask 应用程序,用于在 Heroku 上提供 D3 可视化。我的可视化在这里工作:http://wsankey.github.io/dew_mvp/ 和 Heroku 应用程序:https://dew.herokuapp.com/。问题是我的 javascript 没有获取静态 json 数据——甚至没有抛出错误。地图数据是“us.json”,我的数据是“dewmvp1.json”。
这是 D3 javascript 文件的相关部分:
$(document).ready(function() {
//Reading map file and data
queue()
.defer(d3.json, "/static/us.json")
.defer(d3.json, "/static/dewmvpv1.json")
.await(ready);
还有我的 app.py 文件,我认为我可能会在其中路由数据:
from flask import Flask, render_template
app = Flask(__name__)
#Main DEW page
@app.route('/')
def home():
return render_template("index.html")
#About page
@app.route('/about')
def about():
return render_template("about.html")
#Sending the us.json file
@app.route('/usmap/')
def usmap():
return "<a href=%s>file</a>" % url_for('static', filename='us.json')
#Sending our data
@app.route('/data/')
def data():
return "<a href=%s>file</a>" % url_for('static', filename='dewmvp1.json')
if __name__ == '__main__':
app.run(debug=True)
以及我的 script.js 正在加载的 index.html 的相关部分(让您了解我是如何加载它的):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="http://d3js.org/queue.v1.min.js" type="text/javascript">
<link href="{{url_for('static', filename='topojson.v1.min.js')}}" type="text/javascript">
<link href="{{url_for('static', filename='underscore-1.6.0.min.js')}}" type="text/javascript">
<link href="{{url_for('static', filename='jquery-1.10.2.min.js')}}" type="text/javascript">
<link href="{{url_for('static', filename='jquery-ui-1.10.4.js')}}" type="text/javascript">
<link href='https://fonts.googleapis.com/css?family=Arvo:400,700|PT+Sans+Caption' rel='stylesheet' type='text/css'>
<link rel="stylesheet" media="screen" href="{{url_for('static', filename='jquery-ui-1.10.4.css')}}">
<link rel="stylesheet" media="screen" href="{{url_for('static', filename='grid.css')}}">
<link rel="stylesheet" media="screen" href="{{url_for('static', filename='layout.css')}}">
<link rel="stylesheet" media="screen" href="{{url_for('static', filename='map.css')}}">
<link rel="stylesheet" media="screen" href="{{url_for('static', filename='normalize.css')}}">
<link rel="stylesheet" media="screen" href="{{url_for('static', filename='elements.css')}}">
<link rel="stylesheet" media="screen" href="{{url_for('static', filename='typography.css')}}">
<link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Merriweather' rel='stylesheet' type='text/css'>
<link href="{{url_for('static', filename='d3.min.js')}}" type="text/javascript">
谢谢!
【问题讨论】:
标签: python json heroku d3.js flask