Error during template rendering

Error during template rendering…
views.py
from django.shortcuts import render
from MyApp.models import CategoryDB, ProductDB

Create your views here.

def homepage(request):
data = CategoryDB.objects.all()
return render(request,“home.html”,{‘data’:data})
def aboutpage(request):
return render(request,“about.html”)
def productpage(request,catg):
prod = ProductDB.objects.filter(Category_Name=catg)
return render(request,“products.html”, {‘prod’:prod})

urls.py
from django.urls import path
from webapp import views

urlpatterns=[
path(‘homepage/’,views.homepage, name=“homepage”),
path(‘aboutpage/’, views.aboutpage, name=“aboutpage”),
path(‘productpage//’, views.productpage, name=“productpage”)

html page

{% for d in data %}
                        <img src="{{d.CategoryImage.url}}" alt="image">


                        <a href="{% url 'productpage' catg=d.CategoryName %}">
                            <span>{{d.CategoryName}}</span>

                        </a>

                    </div>

                </div>
                {% endfor %}

models.py
from django.db import models

Create your models here.

class CategoryDB(models.Model):
CategoryName = models.CharField(max_length=50, null=True, blank= True)
Description = models.CharField(max_length=200, null=True, blank= True)
CategoryImage = models.ImageField(upload_to=“CategoryImages”, null=True, blank=True)

class ProductDB(models.Model):
Category_Name= models.CharField(max_length=100,null=True,blank=True)
Product_Name = models.CharField(max_length=100,null=True,blank=True)
Description = models.CharField(max_length=200,null=True,blank=True)
Quantity = models.IntegerField(null=True,blank=True)
Price= models.IntegerField(null=True,blank=True)
Product_Image = models.ImageField(upload_to=“ProductImages”,null=True,blank=True)

Side note: When posting code, please remember to surround the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```.

Please edit your post to add the lines ``` before and after each file’s code. Also post the complete error message you are receiving.

check if the template file refrenced in the view function exist in the correction location, if the file is missing creat the file or update the view function to provide the right data

check if the template file refrenced in the view function exist in the correction location, if the file is missing creat the file or update the view function to provide the right data

Hopefully, this thing will work as I have been applied ?

The code you provided seems to have a few issues. Here are the errors and their corresponding solutions:

  1. Syntax Error in URLs Configuration: In your urls.py file, the path for productpage is incorrect. The placeholder for the category name is missing. It should be:

pythonCopy code

path('productpage/<str:catg>/', views.productpage, name="productpage")
  1. Syntax Error in HTML Template: In your HTML template, there is a missing opening <div> tag. The corrected code should be:

htmlCopy code

<div>
    <img src="{{d.CategoryImage.url}}" alt="image">
    <a href="{% url 'productpage' catg=d.CategoryName %}">
        <span>{{d.CategoryName}}</span>
    </a>
</div>
  1. Incorrect File Upload Paths: In your models.py file, the upload paths for the CategoryImage and Product_Image fields are using incorrect quotation marks. Instead of curly quotes (“”), you should use regular double quotes (“”). Corrected code:

pythonCopy code

CategoryImage = models.ImageField(upload_to="CategoryImages", null=True, blank=True)
...
Product_Image = models.ImageField(upload_to="ProductImages", null=True, blank=True)

Make sure to apply these corrections to your code, and it should resolve the issues you were facing.

@Jackjohn - Actually, these issues you reference are caused by the code in the post not being properly fenced off with the lines of three backtick characters. (I can see the raw post - it actually is correct, it’s just not rendered correctly in the forum as-is. That is why I requested he correct his post in my original response.)