Answer the question
In order to leave comments, you need to log in
Why can't I display the model in the template?
Using Django 1.9
I want to pull all the data from my database.
My Model:
class content(models.Model):
title = models.CharField(max_length=255)
subTitle = models.CharField(max_length=200)
contactTitle = models.CharField(max_length=255)
address = models.TextField(max_length=500)
subAddress = models.TextField(max_length=300)
def __str__(self):
return self.title
def main(request):
queryset = content.objects.all()
context = {
"content": queryset
}
return render(request, "content/index.html", context)
<div class="content-section-a">
<div class="container">
<div class="row">
<div class="col-lg-5 col-sm-6">
<hr class="section-heading-spacer">
<div class="clearfix"></div>
<h2 class="section-heading">{{ content.title }}</h2>
<p class="lead">{{ content.address }}
<ul>
<li>{{ content.subAddress }}</li>
</ul>
</p>
</div>
<div class="col-lg-5 col-lg-offset-2 col-sm-6">
<img class="img-responsive" src="{% static 'content/img/logo.png' %}" alt="">
</div>
</div>
</div>
<!-- /.container -->
</div>
Answer the question
In order to leave comments, you need to log in
В переменной queryset содержится массив объектов класса content, а в шаблоне вы работаете с данными так, будто там только одно значение. Либо вставьте в шаблон цикл, либо замените .all() на .first().
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question