Home > OS >  Rendering Values in Html using Python Django
Rendering Values in Html using Python Django

Time:07-16

** HTML FILE **

    {% extends 'shop/layouts/main.html' %} {% block content %}
<div >
  <div >
    <div >
      <h1>Collections</h1>
      {% for item in items %}
      {{ item.name }}
      {% endfor %}
    </div>
  </div>
</div>
{% endblock content %}

** VIEWS.PY FILE **

from django.shortcuts import render
from . models import *


def collections(request):
    items = Product.objects.all()
    return render(request, "shop/collections.html", {"Item": items})

I need an help that I couldn't load my {items} on html it simply shows nothing in the output

CodePudding user response:

Your context says Item but your templates tries to access items - make sure the names match and it should work.

  • Related