Python图书商城(可运行代码)有说明文档

Python图书商城(可运行代码)有说明文档,第1张

 前端使用了Django框架,结合sqlite数据库,且具有项目配置文档说明,实践项目小白专属。

可运行,欢迎购买,留言可以免费指导配置。

可在线模拟整个购书过程,并且主页包含了基于图书(商品)自身的协同过滤推荐算法对图书进行推荐。

完整的前后台模式,实现管理员对图书进行管理。

【部分代码实现】

片段1:

def index(request):
    # 查询各个分类的最新4条,最热4条数据
    typelist = TypeInfo.objects.all()
    #  _set 连表 *** 作
    type0 = typelist[0].goodsinfo_set.order_by('-id')[0:4]  # 图书的ID号,按照上传顺序自动排序
    type01 = typelist[0].goodsinfo_set.order_by('-gclick')[0:4]  # 按照点击量
    type1 = typelist[1].goodsinfo_set.order_by('-id')[0:4]
    type11 = typelist[1].goodsinfo_set.order_by('-gclick')[0:4]
    type2 = typelist[2].goodsinfo_set.order_by('-id')[0:4]
    type21 = typelist[2].goodsinfo_set.order_by('-gclick')[0:4]
    type3 = typelist[3].goodsinfo_set.order_by('-id')[0:4]
    type31 = typelist[3].goodsinfo_set.order_by('-gclick')[0:4]
    type4 = typelist[4].goodsinfo_set.order_by('-id')[0:4]
    type41 = typelist[4].goodsinfo_set.order_by('-gclick')[0:4]
    type5 = typelist[5].goodsinfo_set.order_by('-id')[0:4]
    type51 = typelist[5].goodsinfo_set.order_by('-gclick')[0:4]


    increase=GoodsInfo.objects.all().order_by('-gclick')[5:10]

    cart_num = 0
    # 判断是否存在登录状态
    # if request.session.has_key('user_id'):
    if 'user_id' in request.session:
        user_id = request.session['user_id']
        cart_num = CartInfo.objects.filter(user_id=int(user_id)).count()

    context = {
        'title': '首页',
        'cart_num': cart_num,
        'guest_cart': 1,
        'type0': type0, 'type01': type01,
        'type1': type1, 'type11': type11,
        'type2': type2, 'type21': type21,
        'type3': type3, 'type31': type31,
        'type4': type4, 'type41': type41,
        'type5': type5, 'type51': type51,
        'increase': increase,
    }

    return render(request, 'df_goods/index.html', context)

片段2:

def good_list(request, tid, pindex, sort):
    # tid:商品种类信息  pindex:商品页码 sort:商品显示分类方式
    typeinfo = TypeInfo.objects.get(pk=int(tid))


    news = typeinfo.goodsinfo_set.order_by('-id')[0:2]
    goods_list = []
    cart_num, guest_cart = 0, 0

    try:
        user_id = request.session['user_id']
    except:
        user_id = None
    if user_id:
        guest_cart = 1
        cart_num = CartInfo.objects.filter(user_id=int(user_id)).count()

    if sort == '1':  # 默认最新
        goods_list = GoodsInfo.objects.filter(gtype_id=int(tid)).order_by('-id')
    elif sort == '2':  # 按照价格
        goods_list = GoodsInfo.objects.filter(gtype_id=int(tid)).order_by('-gprice')
    elif sort == '3':  # 按照人气点击量
        goods_list = GoodsInfo.objects.filter(gtype_id=int(tid)).order_by('-gclick')

    # 创建Paginator一个分页对象
    paginator = Paginator(goods_list, 4)
    # 返回Page对象,包含图书信息
    page = paginator.page(int(pindex))
    context = {
        'title': '商品列表',
        'guest_cart': guest_cart,
        'cart_num': cart_num, #购物车编号
        'page': page, #页数
        'paginator': paginator, #分页对象
        'typeinfo': typeinfo, #类别
        'sort': sort,  # 排序方式
        'news': news,
    }
    return render(request, 'df_goods/list.html', context)

【实现效果图】

 

源代码下载地址:https://download.csdn.net/download/qq_40129714/20432370

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/869388.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存