商品主页页面

商品主页页面的前端页面 效果图如下:

 05 商品模块

后端视图的业务逻辑处理:

根据前端展示的页面,后端需要向前端传送的数据有:

  1 后端需要想前端传送的数据有
  2 全部商品额分类信息
  3 轮播图的数据
  4 广告的信息
  5 分类商品展示的标题和图片
  6 用户购物车的信息

视图 IndexView 函数的代码如下:

from django.shortcuts import render
from django.views.generic import View
from .models import GoodsCategory,IndexGoodsBanner,IndexPromotionBanner
from .models import IndexCategoryGoodsBanner

class IndexView(View):
    def get(self,request):
        # 后端需要想前端传送的数据有
        # 全部商品额分类信息
        # 轮播图的数据
        # 广告的信息
        # 分类商品展示的标题和图片
        # 用户购物车的信息

        # 获取所有的商品分类
        goods_cate=GoodsCategory.objects.all()
        # 获取轮播图信息
        index_banner = IndexGoodsBanner.objects.all().order_by("index")
        # 获取广告的信息
        promotinon_banners=IndexPromotionBanner.objects.all().order_by("index")

        for category in goods_cate:
            # 主页分类商品的标题
            category_title=IndexCategoryGoodsBanner.objects.filter(category=category,display_type=0)[:4]
            category.title = category_title
            category_image=IndexCategoryGoodsBanner.objects.filter(category=category,display_type=1)[:4]
            category.img = category_image

        # 先把购物车的数量 设置为0
        cart_num = 0
        context = {
            "goods_cate":goods_cate,
            "index_banners":index_banner,
            "promotinon_banners":promotinon_banners,
            "cart_num":cart_num
        }


        return render(request,'index.html',context)
View Code

 

前端模板商品分类要填充的代码如下:

<ul class="subnav fl">
    {% for cate in goods_cate %}
       <li><a href="#model0{{ forloop.counter }}" class="{{ cate.logo }}">{{ cate.name }}</a></li>
    {% endfor %}
</ul>
View Code

相关文章:

猜你喜欢
相关资源
相似解决方案