Answer the question
In order to leave comments, you need to log in
How to go to a page by Slug?
How to navigate to a page created with detailview in html?
view.py
class ProductDet(DetailView):
model = Product
context_object_name = 'product'
template_name = 'detail_prod.html'
urls.py
urlpatterns = [
path('', Homepage.as_view(), name='homepage'),
path('<slug:slug>/', ProductDet.as_view(), name='product'),
]
models.py
class Product(models.Model):
title = models.CharField(max_length=255)
description = models.TextField(blank=True, null=True)
price = models.DecimalField(max_digits=9, decimal_places=0)
img = models.ImageField(upload_to='photos/%y/%m/', blank=True)
category = models.ForeignKey('Category', on_delete=models.CASCADE)
slug = models.SlugField(unique=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question