• django开发商城(提供初始数据,商城首页及购物车)


    1.爬取数据

    2.json数据转化为sql语句

    3.新建轮播图模型(模型名与sql语句对应表名相同)

    class Wheel(models.Model):
        img=models.CharField(max_length=150)
        name=models.CharField(max_length=20)
        trackid=models.CharField(max_length=20)

    4.终端打开mysql,执行插入语句

    5.在首页进行展示轮播图(home.html)

          <div class="swiper-container" id="topSlider">
            <div class="swiper-wrapper">
                {% for item in sliderList %}
                <div class="swiper-slide">
                    <a href="#"><img src="{{ item.img }}"></a>
                </div>
                {% endfor %}
            </div>
        </div>

    设置轮播(home.js)

    $(document).ready(function () {
        var swiper = new Swiper('#topSlider', {
            direction: 'horizontal',
            loop: true,
            speed: 500,
            autoplay: 2000,
            pagination: {
                el: '.swiper-pagination',
            }
    
        })
    
    })

    6.展示主要商品

    建立模型,在数据库进行插入

    class MainShow(models.Model):
        trackid = models.CharField(max_length=10)
        name = models.CharField(max_length=20)
        img = models.CharField(max_length=100)
        categoryid = models.CharField(max_length=10)
        brandname = models.CharField(max_length=20)
    
        img1 = models.CharField(max_length=100)
        childcid1 = models.CharField(max_length=10)
        productid1 = models.CharField(max_length=10)
        longname1 = models.CharField(max_length=50)
        price1 = models.CharField(max_length=10)
        marketprice1 = models.CharField(max_length=10)
    
        img2 = models.CharField(max_length=100)
        childcid2 = models.CharField(max_length=10)
        productid2 = models.CharField(max_length=10)
        longname2 = models.CharField(max_length=50)
        price2 = models.CharField(max_length=10)
        marketprice2 = models.CharField(max_length=10)
    
        img3 = models.CharField(max_length=100)
        childcid3 = models.CharField(max_length=10)
        productid3 = models.CharField(max_length=10)
        longname3 = models.CharField(max_length=50)
        price3 = models.CharField(max_length=10)
        marketprice3 = models.CharField(max_length=10)

    进行展示

            {#  mainShow #}
            <section class="mainInfo">
                {% for item in mainShowList %}
                <section>
                    <h3>
                        {{ item.name }}
                        <a href="#">更多&gt;</a>
                        <span></span>
                    </h3>
                    <div>
                        <a href="#"><img src="{{ item.img }}">
                        </a>
                    </div>
                    <ul>
                        <li><a href="">
                            <img src="{{ item.img1}}" alt="">
                            <span class="">
                            {{ item.longname1 }}
                        </span>
                        <span>
                            ¥{{ item.price1 }}<s>¥{{ item.marketprice1 }}</s>
                        </span>
                        </a></li>
                         <li><a href="">
                            <img src="{{ item.img2}}" alt="">
                            <span class="description">
                            {{ item.longname2 }}
                        </span>
                        <span>
                            ¥{{ item.price2 }}<s>¥{{ item.marketprice2 }}</s>
                        </span>
                        </a></li>
                         <li><a href="">
                            <img src="{{ item.img3}}" alt="">
                            <span class="description">
                            {{ item.longname3 }}
                        </span>
                        <span>
                            ¥{{ item.price3 }}<s>¥{{ item.marketprice3 }}</s>
                        </span>
                        </a></li>
                    </ul>
                </section>
                {% endfor %}
            </section>
  • 相关阅读:
    ftp卡死问题
    Windows 10 安装FileZilla Server
    The last packet successfully received from the server was 39,900 milliseconds ago问题解决
    java.sql.SQLException: Could not retrieve transaction read-only status from server 问题解决
    三主机配置 keepalived VIP高可用
    subprocess.Popen在win10下会有异常
    python 使用内置方法读取注册表
    过年有感
    java.security.InvalidKeyException: Illegal key size 解决办法
    Android Studio 检查Top Activity
  • 原文地址:https://www.cnblogs.com/hhy-love-python/p/8555384.html
Copyright © 2020-2023  润新知