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="#">更多></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>