title: How to hide image from Django template?
body: <p>I'm trying to make a blog website. On the all post page, it renders all the posts from the database. But not all post has its feature image. So, I'm trying to hide those image sections that don't have any featured images.</p>
  <p>Here is <strong>blog/model.py</strong></p>
  <pre><code>class Article(models.Model):
  STATUS_CHOICES = (
      ('draft', 'Draft'),
      ('published', 'Published'),
  )
  author = models.ForeignKey(Profile, null=True, blank=True, on_delete=models.SET_NULL)
  title = models.CharField(max_length=200)
  slug = AutoSlugField(populate_from='title', unique=True, null=False, db_index=True)
  excerpt = models.CharField(max_length=60)
  featured_image = models.ImageField(upload_to=&quot;posts&quot;, null=True, blank=True, default=&quot;default.jpg&quot;)
  content = FroalaField()
  created = models.DateTimeField(auto_now_add=True)
  last_update = models.DateTimeField(auto_now=True)
  publish = models.DateTimeField(default=timezone.now)
  status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='draft')
  </code></pre>
  <p>Here is <strong>blog/view.py</strong></p>
  <pre><code># display all blog posts
  def posts(request):
      all_posts = Article.published.all()
      context = {'all_posts': all_posts}
      return render(request, 'blog/posts.html', context)
  
  
  # Single post
  def single_post(request, slug):
      post = Article.objects.get(slug=slug)
      context = {
          'post': post,
      }
      return render(request, 'blog/single-post.html', context)
  </code></pre>
  <p>Here is <strong>blog/url.py</strong></p>
  <pre><code>urlpatterns = [
      path('', views.posts, name=&quot;posts&quot;),
      path('post/&lt;slug:slug&gt;/', views.single_post, name=&quot;single-post&quot;),
  ]
  </code></pre>
  <p>Here is <strong>post.html</strong></p>
  <pre><code>{% for post in all_posts %}
  &lt;li class=&quot;bg-white px-4 py-6 shadow sm:p-6 sm:rounded-lg&quot;&gt;
    &lt;article aria-labelledby=&quot;question-title-81614&quot;&gt;
      &lt;a href=&quot;{{ post.get_absolute_url }}&quot;&gt;
        &lt;!-- author details &amp; option menus --&gt;
        &lt;div class=&quot;flex space-x-3&quot;&gt;
          &lt;div class=&quot;flex-shrink-0&quot;&gt;
            &lt;!-- author image --&gt;
            &lt;img
              class=&quot;h-10 w-10 rounded-full&quot;
              src=&quot;{{ post.author.profile.avatar.url }}&quot;
              alt=&quot;&quot;
            /&gt;
          &lt;/div&gt;
          &lt;!-- author name and publish date time --&gt;
          &lt;div class=&quot;min-w-0 flex-1&quot;&gt;
            &lt;p class=&quot;text-sm font-medium text-gray-900&quot;&gt;
              &lt;a href=&quot;#&quot; class=&quot;hover:underline&quot;&gt;Dries Vincent&lt;/a&gt;
            &lt;/p&gt;
            &lt;p class=&quot;text-sm text-gray-500&quot;&gt;
              &lt;time datetime=&quot;{{ post.publish.date }}&quot;
                &gt;{{ post.publish.date }}
              &lt;/time&gt;
            &lt;/p&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;mt-4 space-y-4&quot;&gt;
          {# show image if there is a feature image #}
  
          {% if post.featured_image.url %}
  
          &lt;!-- article images --&gt;
          &lt;img
            class=&quot;object-cover w-full h-64 bg-center rounded-lg&quot;
            src=&quot;{{ post.featured_image.url }}&quot;
            alt=&quot;{{ post.title }}&quot;
          /&gt;
  
          {% endif %}
        &lt;/div&gt;
        &lt;!-- article title --&gt;
        &lt;h1
          id=&quot;question-title-81614&quot;
          class=&quot;mt-4 text-xl font-medium text-gray-900&quot;
        &gt;
          {{ post.title }}
        &lt;/h1&gt;
      &lt;/a&gt;
    &lt;/article&gt;
  &lt;/li&gt;
  {% endfor %}
  </code></pre>
  <p>Here is the image for a better understanding
  <a href="https://i.stack.imgur.com/iOE3o.png" rel="nofollow noreferrer">post.html template page</a></p>