django - 基于类的 View Django + Chartit 中的转换函数 View

标签 django function charts django-generic-views

我有这个函数 View 。

如何在基于类的 View 中转换此函数?

在这种情况下我使用TemplateView?

def linechart(request):
    ds = DataPool(
        series=[{'options': {
            'source': MonthlyWeatherByCity.objects.all()},
            'terms': [
            'month',
            'houston_temp',
            'boston_temp']}
        ])

    cht = Chart(
        datasource=ds,
        series_options=[{'options': {
            'type': 'bar',
            '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('core/linechart.html', {'weatherchart': cht})

返回错误

enter image description here

最佳答案

class MyTemplateView(TemplateView):
    template_name = 'core/linechart.html'

    def get_ds(self):
        return DataPool(...)

    def get_water_chart(self):
        return Chart(datasource=self.get_ds() ...)

    def get_context_data(self, **kwargs):
        context = super(MyTemplateView, self).get_context_data(**kwargs)
        context['weatherchart'] = self.get_water_chart()

        return context

url 中应该是这样的

url(r'^$', MyTemplateView.as_view(), name='index'),

关于django - 基于类的 View Django + Chartit 中的转换函数 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30405236/

相关文章:

r - 如何从尼尔森输出图表?

c# - 使用 NPOI 在 Excel 电子表格中创建图表

python - Django + InnoDB : random failure of model reading

python - 如何确定国际化参数的优先级

Python 字符串 "Modifiers"

php - 如何获取数组中每个数字的阶乘值?

javascript - 将过滤器选择器变量传递给另一个函数

javascript - Highcharts - 标签中的 HTML

Django : ModelForm with conditions

javascript - GWAN 正在修改 jquery.min.js 报错