我无法在django中查看我的模型项,我做的一切都是正确的,但我的模型项我没有显示我的模型
class Quote(models.Model):
todays_Quote = models.CharField(max_length=500, blank=False)
by = models.CharField(max_length=100, blank=False)
created = models.DateTimeField(auto_now=True)
def __str__(self):
return self.todays_Quote我的观点
class home(View):
def get(self, request):
quote = Quote.objects.all()
return render(request, 'home.html', {'qoutes':quote})我的用于呈现它的html
<section>
<div class="col-11">
<div class="text-center">
{% for Quote in quotes %}
<h1>{{ Quote.todays_Quote }} hello</h1>
<p style="float: right;">{{ Quote.by }}</p>
<p>Todays Date :- <span id="date"></span></p>
{% endfor %}
</div>
</div>
</section>你知道这有什么问题吗&是的,是我做的迁移
页面源
</nav>
<section>
<div class="col-11">
<div class="text-center">
</div>
</div>
</section> 发布于 2021-09-02 15:20:55
我的观点
class home(View):
def get(self, request):
quote = Quote.objects.all()
return render(request, 'home.html', {'qoutes':quote}) # <--Here您的视图中有一个拼写错误,"qoutes“。
您将"qoutes“键传递到上下文字典中,因此当您尝试在模板中迭代它时:
{% for Quote in quotes %}您的模板无法找到"quotes“,因为它只知道"qoutes”。
https://stackoverflow.com/questions/69032282
复制相似问题