Django Model Instances Not Displaying in Template

I'm having trouble displaying model instances in my Django template. I have created instances of my Tribute model, and they exist in the database. However, when I render my template, the model instances are not being displayed.

Here’s a breakdown of my code:

Model:

from django.db import models
from django.core.validators import URLValidator

class Tribute(models.Model):
    card_styling = models.CharField(max_length=100, blank=True)
    tribute_title = models.CharField(max_length=100, blank=True)
    tribute_text1 = models.TextField(blank=True)
    tribute_text2 = models.TextField(blank=True)
    
    tribute_stripe_link1 = models.URLField(validators=[URLValidator], blank=True)
    tribute_stripe_link2 = models.URLField(validators=[URLValidator], blank=True)
    tribute_stripe_link3 = models.URLField(validators=[URLValidator], blank=True)
    tribute_stripe_link4 = models.URLField(validators=[URLValidator], blank=True)
    tribute_stripe_link5 = models.URLField(validators=[URLValidator], blank=True)
    tribute_stripe_link6 = models.URLField(validators=[URLValidator], blank=True)
    
    tribute_payment_button_class1 = models.CharField(max_length=100, blank=True)
    tribute_payment_button_class2 = models.CharField(max_length=100, blank=True)
    tribute_payment_button_class3 = models.CharField(max_length=100, blank=True)
    tribute_payment_button_class4 = models.CharField(max_length=100, blank=True)
    tribute_payment_button_class5 = models.CharField(max_length=100, blank=True)
    tribute_payment_button_class6 = models.CharField(max_length=100, blank=True)
    
    price1 = models.CharField(max_length=100, blank=True)
    price2 = models.CharField(max_length=100, blank=True)
    price3 = models.CharField(max_length=100, blank=True)
    price4 = models.CharField(max_length=100, blank=True)
    price5 = models.CharField(max_length=100, blank=True)
    price6 = models.CharField(max_length=100, blank=True)

    def __str__(self):
        return self.tribute_title or 'Unnamed Tribute'

View:

from django.shortcuts import render
from .models import Tribute

def tribute_view(request):
    # Get all Tribute objects
    tributes = Tribute.objects.all()

    # Pass the Tribute objects to the template context
    context = {
        'tributes': tributes
    }
    
    return render(request, 'shop7/shop(with_models).html', context)

Template

{% extends 'shop7/base.html' %}
{% load static %}

{% block body %}
<div class="container card-container-top">
    <div class="row">
        {% for tribute in tributes %}
        <div class="col-md-4">
            <div id="{{ tribute.card_styling }}" class="card">
                <div class="card-body">
                    <div class="card-text-styling">
                        <h5 class="card-title">{{ tribute.tribute_title }}</h5>
                        <p class="card-text"><strong>Helps with:</strong> {{ tribute.tribute_text1 }}<br> </p>
                        <p class="card-text"><strong>Fights against:</strong> {{ tribute.tribute_text2 }}<br></p>
                    </div>
                    <a href="{{ tribute.tribute_stripe_link1 }}" class="btn {{ tribute.tribute_payment_button_class1 }}">{{ tribute.price1 }}</a>
                    <a href="{{ tribute.tribute_stripe_link2 }}" class="btn {{ tribute.tribute_payment_button_class2 }}">{{ tribute.price2 }}</a>
                    <a href="{{ tribute.tribute_stripe_link3 }}" class="btn {{ tribute.tribute_payment_button_class3 }}">{{ tribute.price3 }}</a>
                    <a href="{{ tribute.tribute_stripe_link4 }}" class="btn {{ tribute.tribute_payment_button_class4 }}">{{ tribute.price4 }}</a>
                    <a href="{{ tribute.tribute_stripe_link5 }}" class="btn {{ tribute.tribute_payment_button_class5 }}">{{ tribute.price5 }}</a>
                    <a href="{{ tribute.tribute_stripe_link6 }}" class="btn {{ tribute.tribute_payment_button_class6 }}">{{ tribute.price6 }}</a>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
</div>

<div class="container card-container-other">
    <div class="row">
        {% for tribute in tributes %}
        <div class="col-md-3">
            <div id="{{ tribute.card_styling }}" class="card">
                <div class="card-body">
                    <div class="card-text-styling">
                        <h5 class="card-title">{{ tribute.tribute_title }}</h5>
                        <p class="card-text"><strong>Helps with:</strong> {{ tribute.tribute_text1 }}<br>
                        <strong>Fights against:</strong> {{ tribute.tribute_text2 }}<br></p>
                    </div>
                    <a href="{{ tribute.tribute_stripe_link1 }}" class="btn {{ tribute.tribute_payment_button_class1 }}">{{ tribute.price1 }}</a>
                    <a href="{{ tribute.tribute_stripe_link2 }}" class="btn {{ tribute.tribute_payment_button_class2 }}">{{ tribute.price2 }}</a>
                    <a href="{{ tribute.tribute_stripe_link3 }}" class="btn {{ tribute.tribute_payment_button_class3 }}">{{ tribute.price3 }}</a>
                    <a href="{{ tribute.tribute_stripe_link4 }}" class="btn {{ tribute.tribute_payment_button_class4 }}">{{ tribute.price4 }}</a>
                    <a href="{{ tribute.tribute_stripe_link5 }}" class="btn {{ tribute.tribute_payment_button_class5 }}">{{ tribute.price5 }}</a>
                    <a href="{{ tribute.tribute_stripe_link6 }}" class="btn {{ tribute.tribute_payment_button_class6 }}">{{ tribute.price6 }}</a>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
</div>

{% endblock body %}

URL config:

from django.urls import path
from . import views

urlpatterns = [
    path('', views.tribute_view, name="shop"),
    path('shop/', views.tribute_view, name="shop"),
    path('temples/', views.temples_view, name="temples"),
    path('membership/', views.membership_view, name="membership"),
    path('add-product/', views.add_product, name="add_product"),
]

Issue:

Despite having created instances of the Tribute model and confirming their presence in the database, these instances are not appearing on my template page.

Steps I've Taken:

Verified that model instances exist in the database. Ensured the view is correctly querying and passing data to the template. Checked that the template is correctly using the context data. Questions:

Are there any obvious mistakes in my view or template code?

Could there be an issue with how the URL is configured or the template file path?

Back to Top