How can i use django template tag to view some thing that i have created in database?

When i create multiple product i can see my <div class='card'> content in browser. But i can not see the values that i have submited in my database fields. For example i have created a product in admin page with number of 1 since i have specified {{pr.number}} in my template.

how can i see the values of database fields that i added in admin page in my templates?

template:

{% load static %}
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet"   href="{% static 'main.css' %}">
</head>
<body>
    {% for i in pr%} 
        <div class='card'>
            <div class="number">{{pr.number}}</div>
            <img src="{% static '3307209.jpg'%}">
            <span class="prname">{{pr.name}}</span>
            
            <p id="id">{{pr.description}}</p>
            <button><span class="price"> {{pr.price}}</span> <img id='add'src="{% static 'add.png'%}"> Add to cart</button>
        </div>
    {%endfor%}
</body>
</html>

models:

from django.db import models

# Create your models here.
class product(models.Model):
    number=models.IntegerField()
    name=models.CharField(max_length=20)
    description=models.CharField(max_length=150)
    price=models.IntegerField()

views:

from django.shortcuts import render
from .models import product

# Create your views here.
def a (request):



    db=product.objects.all()
    return render (request,'main page.html',{'pr':db})

Your for syntax is incorrect Use it this way:

{% load static %}
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet"   href="{% static 'main.css' %}">
</head>
<body>
    {% for i in pr%} 
        <div class='card'>
            <div class="number">{{i.number}}</div>
            <img src="{% static '3307209.jpg'%}">
            <span class="prname">{{i.name}}</span>
            
            <p id="id">{{i.description}}</p>
            <button><span class="price"> {{i.price}}</span> <img id='add'src="{% static 'add.png'%}"> Add to cart</button>
        </div>
    {%endfor%}
</body>
</html>
Back to Top