this is models.py
from django.db import models
# Create your models here.
class Products(models.Model):
name_product=models.CharField(max_length=100)
category_product=models.CharField(max_length=100)
price_product=models.CharField(max_length=200)
image_product=models.ImageField(default='Image.png',upload_to='web/')
description_product=models.CharField(max_length=400)
this is views.py
from django.shortcuts import render
from .models import Products
# Create your views here.
def asli(request):
data=Products.objects.all()
return render(request,'home.html',{'data':data})
this is my web page
<img src="{{ data.image_product.url }}" alt="Product Image">
I tried this code in the setting.py but still it doesn’t show my photos on my web page
P.s: The connection has been established correctly
MEDIA_URL = "media/"
MEDIA_ROOT = BASE_DIR / "media"
New contributor
shahrzad shakiba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.