我正在尝试在Django中使用基于类的视图!
我的urls.py:
path('pie-chart/', views.pie_chart, name='pie_chart.html'),
我的view.py
class pie_chart(View):
def __init__(self, labels, data):
self.labels = labels
self.data = data
def active_sessions(self, request):
self.labels = []
self.data = []
queryset = Employees.objects.values('department__name').annotate(total_session=Count('employeeconnection__employeesession'))
for item in queryset:
self.labels.append(item['department__name'])
self.data.append(item['total_session'])
return render(request, 'pie_chart.html', {
'labels': self.labels,
'data': self.data,
})
我收到此错误:
__init__() missing 1 required positional argument: 'data'
path('pie-chart/', views.pie_chart.as_view(), name='pie_chart.html'),
更正网址