DEV Community

Discussion on: #solved Data not showing on Django Template

Collapse
 
highcenburg profile image
Vicente G. Reyes

Ok so I removed the other Volunteer.objects.all() already. I would send those to the template. Just not on this model. How am I supposed to send the data form my database then?

Collapse
 
olaoluwa98 profile image
Emmanuel Awotunde

I think you can restructure your view to look like this:

def home(request):
    aml_videos = AMLVideo.objects.filter().order_by("-category", "-language", "-level")
    volunteers = Volunteer.objects.all()
    context = {'aml_videos': aml_videos, 'volunteers': volunteers}
    return render(request, "aml/home.html", context)

Then your template would look like this:

 <div class="row">
    {% for volunteer in volunteers %}
        <div class="col-md-4 col-sm-6">
            <div class="team-wrapper">
                <div class="team-img">
                    <img src="{{ volunteer.img.url }}" class="img-responsive" alt="Image">
                </div><!-- /.team-img -->

                <div class="team-title">
                    <h3><a href="#">{{ volunteer.name }}</a></h3>
                </div><!-- /.team-title -->

            </div><!-- /.team-wrapper -->
        </div><!-- /.col-md-4 -->
    {% endfor %}
</div><!-- /.row -->
Thread Thread
 
highcenburg profile image
Vicente G. Reyes

This solved the problem. Thank you!

Thread Thread
 
olaoluwa98 profile image
Emmanuel Awotunde

Anytime!

Thread Thread
 
preciselyalyss profile image
Alyss 💜

Thanks for helping folks out and welcome to Dev.to!

Thread Thread
 
olaoluwa98 profile image
Emmanuel Awotunde

My pleasure!