Django 1.8 calls to database in html code
<p>long-time lurker for this website, but I finally decided to join the community.</p>

<p>I have a quick question on some of my code. I took a job this year for my university developing a website for the journalist department. The website was being built the previous year by another student using Django 1.8, python 2, and everything else that comes with that. I knew a decent amount about these languages, and I have learned a lot testing out different methods for hours on end. However, there is one thing I am having trouble with that I have researched for forever.</p>

<p>Basically, for my website, I have different "sections" for different pages of articles. These articles have many traits. One trait is called "section" and this section has the names of the pages. So for example:</p>

<p>One page is named "look". I can call my code and display all of my featured_articles. HOWEVER, I am trying to only display the articles where the name of the section equals "look".</p>

<p>Here is my current code. Any ideas? I have tried many things but I can't get it to work properly. For loops, if statements, different HTML processes, different pages in django, etc...</p>

<pre><code>{% for article, section in featured_articles %}
&lt;div class="media panel panel-default"&gt;
    &lt;div class="panel-body"&gt;
        &lt;div class="media-left"&gt;
            &lt;a href="articles/{{ article.url }}"&gt;
                &lt;img class="media-object thumbnail-featured"
                     src="{{ article.image }}"&gt;
             &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="media-body"&gt;
            &lt;a href="articles/{{ article.url }}"&gt;
                &lt;h3 class="media-heading"&gt;{{ article.title }}&lt;/h3&gt;
            &lt;/a&gt;


            &lt;!-- TODO figure out how to iterate through the authors field, manytomany --&gt;
            {% for contributor in article.authors.all %}
                &lt;p&gt;&lt;a href="/{{ section.url }}"&gt;{{ section.name }}&lt;/a&gt; |
                   &lt;a href="/contributors/{{ contributor.twitter }}"&gt;{{contributor}}&lt;/a&gt;&lt;/p&gt;
            {% endfor %}

            &lt;p&gt;{{article.preview}}&lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
{% endfor %}
</code></pre>

<p>Thank you for any help!!</p>

<p>As I understand, you just need to add if statement:</p>

<pre><code>{% for article, section in featured_articles %}
{% if section.name == 'look' %}
&lt;div class="media panel panel-default"&gt;
    &lt;div class="panel-body"&gt;
        &lt;div class="media-left"&gt;
            &lt;a href="articles/{{ article.url }}"&gt;
                &lt;img class="media-object thumbnail-featured"
                     src="{{ article.image }}"&gt;
             &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="media-body"&gt;
            &lt;a href="articles/{{ article.url }}"&gt;
                &lt;h3 class="media-heading"&gt;{{ article.title }}&lt;/h3&gt;
            &lt;/a&gt;


                &lt;!-- TODO figure out how to iterate through the authors field, manytomany --&gt;
                {% for contributor in article.authors.all %}
                &lt;p&gt;&lt;a href="/{{ section.url }}"&gt;{{ section.name }}&lt;/a&gt; |
                    &lt;a href="/contributors/{{ contributor.twitter }}"&gt;{{           contributor }}&lt;/a&gt; &lt;/p&gt;
                    {% endfor %}

                          &lt;p&gt;{{article.preview}}&lt;/p&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
{% endif %}
{% endfor %}
</code></pre>

python html django