gpt4 book ai didi

python - 使用 Python 2.7 在 Django 1.6 中实现 chartit - TypeError : 'NoneType' has no attribute __getitem__

转载 作者:行者123 更新时间:2023-11-28 19:22:16 24 4
gpt4 key购买 nike

我已经在 Django 中成功地实现了一些应用程序。目前我尝试根据教程实现图表:http://chartit.shutupandship.com/docs/#how-to-use .

但我只收到此错误消息:

Exception Value: 'NoneType' object has no attribute '__getitem__'
Exception Location: /home/administrator/virtualenvs/django27/lib/python2.7/site-packages/chartit/templatetags/chartit.py in load_charts, line 68

失败出现在这一行: hco['图表']['renderTo'] = render_to

错误是否表明 render_to 不是字典?

模型.py:

Class MonthlyWeatherByCity(models.Model):
month = models.IntegerField()
boston_temp = models.DecimalField(max_digits=5, decimal_places=1)
houston_temp = models.DecimalField(max_digits=5, decimal_places=1)

views.py:

def weather_chart_view(request):
#Step 1: Create a DataPool with the data we want to retrieve.
weatherdata = \
DataPool(
series=
[{'options': {
'source': MonthlyWeatherByCity.objects.all()},
'terms': [
'month',
'houston_temp',
'boston_temp']}
])

#Step 2: Create the Chart object
cht = Chart(
datasource = weatherdata,
series_options =
[{'options':{
'type': 'line',
'stacking': False},
'terms':{
'month': [
'boston_temp',
'houston_temp']
}}],
chart_options =
{'title': {
'text': 'Weather Data of Boston and Houston'},
'xAxis': {
'title': {
'text': 'Month number'}}})

我在模板中包含了脚本文件,{{ load block }} ..

<div id='container'> {{ weatherchart|load_charts:"container" }} </div>

<script type="text/javascript" src="/static/js/jquery-1.11.0.js"></script>
<script type="text/javascript" src="/static/js/highcharts.js"></script>

但我认为这不是问题所在。

我该如何解决?谢谢!

最佳答案

尝试将 {{ weatherchart|load_charts:"container"}} 行从 ID 为 containerdiv 移出并移入header,比如 example

关于python - 使用 Python 2.7 在 Django 1.6 中实现 chartit - TypeError : 'NoneType' has no attribute __getitem__,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22374701/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com