gpt4 book ai didi

python - Chartit 不是有效的标签库 :Django

转载 作者:太空狗 更新时间:2023-10-30 00:21:54 25 4
gpt4 key购买 nike

我的views.py文件如下:

from django.shortcuts import render, render_to_response
from chartit import DataPool, Chart
from chartit.chartdata import DataPool
from weather.models import MonthlyWeatherByCity
import simplejson
from chartit import DataPool, Chart

def weather_chart_view(request):
ds=DataPool(series=[{'options': {'source': MonthlyWeatherByCity.objects.all()},'terms': ['month','houston_temp','boston_temp']}])
cht = Chart(datasource = ds, 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'}}})
return render_to_response('chart.html',{'weatherchart': cht})

应用内的urls.py文件如下:

from django.conf.urls import include, url
from django.contrib import admin
from weather import views

urlpatterns = [
url(r'^$', views.weather_chart_view , name='weather_chart_view')
]

models.py文件如下:

from django.db import models

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)

chart.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 %}
{{ weatherchart|load_charts:"container" }}
</head>
<body>
<div id='container'> {{ weatherchart|load_charts:"container" }}</div>
</body>

在运行服务器并打开应用程序时出现错误:

TemplateSyntaxError at /weather/
'chartit' is not a valid tag library: ImportError raised loading chartit.templatetags.chartit: cannot import name simplejson

我还在 INSTALLED_APPS 中包含了应用程序、chartit 和 json。

如您所见,我还在 View 中导入了 simplejson。我哪里错了?

请建议我是否需要发布任何其他内容以使问题清晰。

最佳答案

项目的 github 页面上有一个问题的修复程序。执行 pip install simplejson,然后在 chartit 模块中找到文件 chartit/templatetags/chartit.py 并替换 simplejson 导入行,如下所示。

from django import template
-from django.utils import simplejson
+import simplejson
from django.utils.safestring import mark_safe

它看起来像 hack,但在修复合并之前一直有效。

关于python - Chartit 不是有效的标签库 :Django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23564529/

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