S
S
s1veme2020-07-25 16:18:07
Django
s1veme, 2020-07-25 16:18:07

In django, for doesn't output anything?

There is an html template, there is for, there are views.
Everything is as it should be, but it still does not display anything.

I am attaching the code.

<section class="content">
          <div class="container-fluid">
            {% for post in posts %}
              <div class="content-header">
                <div class="row">
                  <div class="col-lg-12">
                    <div class="content-header-blog">
                      <h2> {{ post.topic }} </h2>
                      <a href="blog.html">{{ post.article_title }}</a>
                      <p class="description"> {{ post.description }}</p>
                      <h4> {{ post.author }}</h4>
                      <p> {{ post.date }}</p>
                    </div>
                  </div>
                </div>
              </div>
            {% endfor %}
          </div>
      </section>


posts = {
    'topic':'Главная страница блога', 
    'article_title':'Привет', 
    'description':'Описание', 
    'author':'SaveMe', 
    'date':'25.07.2020'
}

data = {
    'posts': posts, 
    'title': 'Привет'
}
def home(request):
    return render(request, 'blog/home.html', data)


If we assume to replace post.topic
With With
posts.topic

Then, the site will have 5 columns with the inscription: Blog homepage

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-07-25
@bacon

Run python, paste your posts there and loop through it, then think about the result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question