【发布时间】:2022-10-02 22:30:01
【问题描述】:
我有一个问题,我无法按类别获取产品详细信息 因为 Views 包含两个变量,我无法让它们显示产品详细信息
模型
from django.db import models
# Create your models here.
class Category(models.Model):
name = models.CharField(max_length=200)
slug = models.CharField(max_length=200)
def __str__(self):
return self.name
class Product(models.Model):
Category = models.ForeignKey(Category, on_delete=models.CASCADE)
name = models.CharField(max_length=200, null=False, blank=False)
slug = models.CharField(max_length=200, null=False, blank=False)
description = models.TextField(max_length=350, null=False, blank=False)
image = models.ImageField( null=False, blank=False)
quantity = models.IntegerField(null=False, blank=False)
def __str__(self):
return self.name
网址
path(\'category/<str:product_category_slug>/<str:product_slug>/\', views.product_detail, name=\"product-detail\")
维维斯
def product_detail(request, product_category_slug=None, product_slug=None):
#How do I get product details through this path that contains a category and then the product
我希望有一个人可以帮助我
标签: django django-views