[英]How to use get_context_data in django
我有Views.py
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'
短信记录器
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应用程序获取数据。 如何通过TemplateView子类实现
您能告诉我们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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.