Django model info not being rendered

I am trying to create an educational website using Django, so when I am trying to render {{ profile.institution }} or {{ profile.grade }} they are not being rendered. Although {{ user.username }} is being rendered. I don't know why they aren't. Can anyone help me solve this?

My models.py:

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    institution = models.CharField(max_length = 100)
    grade = models.CharField(max_length=100, choices= YEAR_IN_SCHOOL_CHOICES)
    bio = models.TextField(max_length=300)

    def __str__(self):
        return f'{self.user.username} Profile'

My views.py:

def User_Profile(request, user):
    model = Profile
    user = request.user
    profile = Profile.objects.filter(user=user)
    context = {'profile': profile}
    return render(request, 'class/profile.html',  context)

My html:

    <div class="container mt-5">
        
        <div class="row d-flex justify-content-center">
            
            <div class="col-md-7">
                
                <div class="card p-3 py-4">
                    
                    <div class="text-center">
                        <i class='fas fa-user-alt' style='font-size:36px'></i>
                        <!-- <img src="" width="100" class="rounded-circle"> -->
                    </div>
                    
                    <div class="text-center mt-3">
                        <span class="bg-secondary p-1 px-4 rounded text-white">Pro</span>
                        <h5 class="mt-2 mb-0">{{ user.username }}</h5>
                        <span>{{ profile.institution }}</span>
                        <span>{{ profile.grade }} Grade</span>

                        
                        <div class="px-4 mt-1">
                            <p class="fonts">{{ profile.bio }}</p>
                        
                        </div>

                        
                        <div class="buttons">
                            
                            <button class="btn btn-outline-primary px-4">Message</button>
                            <button class="btn btn-primary px-4 ms-3">Contact</button>
                        </div>
                        
                        
                    </div>
                    
                   
                    
                    
                </div>
                
            </div>
            
        </div>
        
    </div>

profile = Profile.objects.filter(user=user) will assign a queryset to profile.
To access profile.institution you will need profile to be an object instead of a queryset so you will need to use get instead of filter:
profile = Profile.objects.get(user=user)

Back to Top