[英]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.