class newChartView(TemplateView):
template_name = "new_report_view.html"
def get_context_data(self, **kwargs):
context = super(newChartView, self).get_context_data(**kwargs)
context['count'] = smslogger.objects.all()
return context
和 new_report_view.html 为
{% for x in count %}
{{ x.count }}
{% endfor %}
并显示错误
'module' object has no attribute 'objects'
smsloggger
model
class Log(models.Model):
date= models.DateField()
count=models.CharField(max_length=100)
class Meta:
verbose_name_plural = "SMS Log"
def __unicode__(self):
return self.date,self.count
我想从smslogger app获取数据。我如何通过TemplateView子类
实现它答案 0 :(得分:1)
你能告诉我们smslogger.py包含的内容吗?
我想你可能需要这样做。
from smslogger import YourModel
class newChartView(TemplateView):
template_name = "new_report_view.html"
def get_context_data(self, **kwargs):
context = super(newChartView, self).get_context_data(**kwargs)
context['count'] = YourModel.objects.all()
return context