【发布时间】:2014-07-23 04:26:53
【问题描述】:
我正在使用ChartIt 并在尝试查看 URL 上的图表时不断收到“模板不存在”。本教程正在正确遵循,但可能在某处犯了错误。我是 Django 的新手,所以任何帮助将不胜感激。在调用 def 时,加载图表的请求正在工作。
views.py 文件中的定义。
def lineChart(request):
commitData = \
DataPool(
series=
[{'options': {
'source': TestCommit.objects.all()[:200]}, 'terms': ['author', 'author_time']}])
linechart = Chart(
datasource=commitData,
series_options=
[{'options': {
'type': 'line',
'stacking': False},
'terms': {
'author_time': [
'author_time']
}}],
chart_options=
{'title': {
'text': 'YAYs'},
'xAxis': {
'title': {
'text': 'Month number'}}})
return render_to_response({'testCommits.html': linechart})
testCommits.html
<head>
<!-- code to include the highcharts and jQuery libraries goes here -->
<!-- load_charts filter takes a comma-separated list of id's where -->
<!-- the charts need to be rendered to -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script src="http://code.highcharts.com/highcharts.js" type="text/javascript"></script>
<script src="/highcharts.js" type="text/javascript"></script>
{% load chartit %}
{{ linechart|load_charts:"container" }}
</head>
<body>
<div id='container'> Chart will be rendered here </div>
</body>
【问题讨论】:
-
您是否在
urls.py中映射了您的视图?尝试看看您是否可以使用浏览器访问您的视图。 -
是的,url(r'^lineChart/', dashboard.views.lineChart),
-
我知道它在视图中命中了 def,因为当它在浏览器中加载它时,我可以在堆栈跟踪中看到错误。
-
可能与您的问题无关,但您的视图返回错误。应该是
return render_to_response('testCommits.html', linechart) -
根据指南,这是不正确的,会导致语法错误。
标签: python django highcharts