首页 > 其他分享 >「路飞项目12」

「路飞项目12」

时间:2023-07-03 17:13:59浏览次数:57  
标签:12 14 course 项目 路飞 2022 time id 07

0 双写一致性之定时更新

# 一旦加入缓存,就会出现数据不一致的请请求
# 双写一致性问题
-1 改数据,删缓存
-2 改数据,改缓存
-3 定时更新
    
    
# 首页轮播图存在双写一致性问题这个问题
-以现在的技术水平,数据从后台管理录入,找不到Banner.objects.create()地方,没有办法删缓存,不知道用什么触发条件来删缓存,做不到改数据删缓存。以后学信号就能搞定

-能选择的就是定时更新

-轮播图接口---》实时性要求没有那么高
        
              
# celery的定时任务
-定时更新轮播图
@app.task
# 定时更新
    def update_banner_redis():
        # 查询数据库,拿到所有数据,序列化后放至缓存中
        queryset = Banner.objects.filter(is_show=True, is_delete=False).order_by('orders')[:settings.BANNER_COUNT]
        ser = BannerSerializer(instance=queryset, many=True)
        # 在视图类中做序列化,因为视图类中有request对象,像图片这种会自动加上地址前缀,而这里和request没有关系,需要手动加。
        for item in ser.data:
            item['image'] = f"{settings.BACKEND_URL}{item['image']}"
        # 传入至缓存
        cache.set('banner_list', ser.data)
        return True
      
     
# 定时任务配置
        # 时区
        app.conf.timezone = 'Asia/Shanghai'
        app.conf.enable_utc = False
        # 任务定时
        app.conf.beat_schedule = {
            'banner_redis': {
                'task': 'home.home_task.update_banner_redis',
                'schedule': timedelta(seconds=20),
                'args': (), },
        }

0 异步发送短信

# 视图函数
from .user_task import send_sms_task
@action(methods=['GET'], detail=False)
def send_sms(self, request, *args, **kwargs):
    mobile = request.query_params.get('mobile', None)
    code = get_code()  # 把code存起来,放到缓存中,目前在内存,后期换别的
    cache.set('send_sms_code_%s' % mobile, code)
    if mobile:
        res = send_sms_task.delay(mobile,code)
        return APIResponse(msg='短信已发送')
    raise APIException('手机号没有携带')

# 任务
from celery_module.celery import app
from libs.send_tx_sms import send_sms_by_mobile
@app.task
def send_sms_task(mobile, code):
    res = send_sms_by_mobile(mobile, code)
    if res:
        return f'用户【{mobile}】短信发送成功'
    else:
        return f'用户【{mobile}】短信发送失败'

1 异步秒杀逻辑前后端

# 逻辑:
1.前端点击`秒杀`按钮触发点击事件,发送post请求携带[商品id,用户token]到后端。

2.后端收到请求后,因为开启用了celery,所以很多任务被提交到redis的消息队列,然后返回给前端"排队中ing",此时将任务id保存下来。前端启动定时器,3秒钟发送一个get请求【携带任务id】查询秒杀结果。

3.worker启动后,开始执行被提交的大量任务【扣减库存,生成订单】,根据不同的状态返回不同的结果返回给前端,如果是成功或者失败,前端告诉用户结果并且关闭定时器,如果还未执行任务,不做处理。

1.1 前端 Sckill.vue

<template>
  <div>
    <h2>go语言从入门到放弃</h2>
    <el-button type="danger" @click="handleSckill">秒杀</el-button>

  </div>
</template>

<script>
export default {
  name: "Sckill",
  data() {
    return {
      t: null,
      task_id: '',
    }
  },
  methods: {
    handleSckill() {
      this.$axios.post(`${this.$settings.BASE_URL}user/sckill/`, {
        name: "性感帽子",
      }).then(res => {
        if (res.data.code == 100) {
          alert('您正在排队')
          this.task_id = res.data.task_id
          // 起个转圈的东西
          // 起定时任务
          this.t = setInterval(() => {
            this.$axios.get(`${this.$settings.BASE_URL}user/sckill/?task_id=${this.task_id}`).then(res => {
              if (res.data.code == 100 || res.data.code == 101) {
                this.$message(res.data.msg)
                //销毁定时器
                clearInterval(this.t)
                this.t = null
              } else {
                console.log('过会再查')
              }
            })
          }, 3000)
        }
      })
    }
  }
}
</script>

<style scoped>

</style>

1.2 后端

视图类

from celery_task.user_task import sckill_goods
from celery_task.celery import app
from celery.result import AsyncResult


class SckillView(APIView):
    def post(self, request, *args, **kwargs):
        name = request.data.get('name')
        # 提交秒杀异步任务
        res = sckill_goods.delay(name)
        return APIResponse(task_id=str(res))

    def get(self, request, *args, **kwargs):
        task_id = request.GET.get('task_id')
        a = AsyncResult(id=task_id, app=app)
        if a.successful():  # 正常执行完成
            result = a.get()  # 任务返回的结果
            if result:
                return APIResponse(code=100, msg='秒杀成功')
            else:
                return APIResponse(code=101, msg='秒杀失败')
        elif a.status == 'STARTED':
            print('任务已经开始被执行')
            return APIResponse(code=103, msg='还在排队')
        else:
            return APIResponse(code=102, msg='没成功')

路由

urlpatterns = [
    path('sckill/', SckillView.as_view()),
]

任务

@app.task
def sckill_goods(name):
    # 逻辑是:开启事务---》扣减库存---》生成订单
    import time
    time.sleep(6)
    res = random.choice([100, 102])
    if res == 100:
        print('%s被秒杀成功了' % name)
        return True
    else:
        print('%s被秒杀失败了' % name)
        return False

2 课程页页面前端

# 1 前端  新建三个组件
LightCourse.vue
FreeCourse.vue
ActualCourse.vue
    
# 2 配置路由
	import FreeCourse from "@/views/FreeCourse";
    import ActualCourse from "@/views/ActualCourse";
    import LightCourse from "@/views/LightCourse";
    
     {
        path: '/free-course',
        name: 'free-course',
        component: FreeCourse
    },
    {
        path: '/actual-course',
        name: 'actual-course',
        component: ActualCourse
    },
    {
        path: '/light-course',
        name: 'light-course',
        component: LightCourse
    },

# 3 FreeCourse.vue
<template>
  <div class="course">
    <Header></Header>
    <div class="main">
      <!-- 筛选条件 -->
      <div class="condition">
        <ul class="cate-list">
          <li class="title">课程分类:</li>
          <li class="this">全部</li>
          <li>Python</li>
          <li>Linux运维</li>
          <li>Python进阶</li>
          <li>开发工具</li>
          <li>Go语言</li>
          <li>机器学习</li>
          <li>技术生涯</li>
        </ul>

        <div class="ordering">
          <ul>
            <li class="title">筛&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;选:</li>
            <li class="default this">默认</li>
            <li class="hot">人气</li>
            <li class="price">价格</li>
          </ul>
          <p class="condition-result">共21个课程</p>
        </div>

      </div>
      <!-- 课程列表 -->
      <div class="course-list">
        <div class="course-item">
          <div class="course-image">
            <img src="@/assets/img/course-cover.jpeg" alt="">
          </div>
          <div class="course-info">
            <h3>Python开发21天入门 <span><img src="@/assets/img/avatar1.svg" alt="">100人已加入学习</span></h3>
            <p class="teather-info">Alex 金角大王 老男孩Python教学总监 <span>共154课时/更新完成</span></p>
            <ul class="lesson-list">
              <li><span class="lesson-title">01 | 第1节:初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span></li>
            </ul>
            <div class="pay-box">
              <span class="discount-type">限时免费</span>
              <span class="discount-price">¥6.00元</span>
              <span class="original-price">原价:9.00元</span>
              <span class="buy-now">立即购买</span>
            </div>
          </div>
        </div>
        <div class="course-item">
          <div class="course-image">
            <img src="@/assets/img/course-cover.jpeg" alt="">
          </div>
          <div class="course-info">
            <h3>Python开发21天入门 <span><img src="@/assets/img/avatar1.svg" alt="">100人已加入学习</span></h3>
            <p class="teather-info">Alex 金角大王 老男孩Python教学总监 <span>共154课时/更新完成</span></p>
            <ul class="lesson-list">
              <li><span class="lesson-title">01 | 第1节:初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span></li>
            </ul>
            <div class="pay-box">
              <span class="discount-type">限时免费</span>
              <span class="discount-price">¥0.00元</span>
              <span class="original-price">原价:9.00元</span>
              <span class="buy-now">立即购买</span>
            </div>
          </div>
        </div>
        <div class="course-item">
          <div class="course-image">
            <img src="@/assets/img/course-cover.jpeg" alt="">
          </div>
          <div class="course-info">
            <h3>Python开发21天入门 <span><img src="@/assets/img/avatar1.svg" alt="">100人已加入学习</span></h3>
            <p class="teather-info">Alex 金角大王 老男孩Python教学总监 <span>共154课时/更新完成</span></p>
            <ul class="lesson-list">
              <li><span class="lesson-title">01 | 第1节:初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span></li>
            </ul>
            <div class="pay-box">
              <span class="discount-type">限时免费</span>
              <span class="discount-price">¥0.00元</span>
              <span class="original-price">原价:9.00元</span>
              <span class="buy-now">立即购买</span>
            </div>
          </div>
        </div>
        <div class="course-item">
          <div class="course-image">
            <img src="@/assets/img/course-cover.jpeg" alt="">
          </div>
          <div class="course-info">
            <h3>Python开发21天入门 <span><img src="@/assets/img/avatar1.svg" alt="">100人已加入学习</span></h3>
            <p class="teather-info">Alex 金角大王 老男孩Python教学总监 <span>共154课时/更新完成</span></p>
            <ul class="lesson-list">
              <li><span class="lesson-title">01 | 第1节:初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span> <span class="free">免费</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码</span></li>
              <li><span class="lesson-title">01 | 第1节:初识编码初识编码</span></li>
            </ul>
            <div class="pay-box">
              <span class="discount-type">限时免费</span>
              <span class="discount-price">¥0.00元</span>
              <span class="original-price">原价:9.00元</span>
              <span class="buy-now">立即购买</span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <Footer></Footer>
  </div>
</template>

<script>
import Header from "@/components/Header"
import Footer from "@/components/Footer"

export default {
  name: "Course",
  data() {
    return {
      category: 0,
    }
  },
  components: {
    Header,
    Footer,
  }
}
</script>

<style scoped>
.course {
  background: #f6f6f6;
}

.course .main {
  width: 1100px;
  margin: 35px auto 0;
}

.course .condition {
  margin-bottom: 35px;
  padding: 25px 30px 25px 20px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 4px 0 #f0f0f0;
}

.course .cate-list {
  border-bottom: 1px solid #333;
  border-bottom-color: rgba(51, 51, 51, .05);
  padding-bottom: 18px;
  margin-bottom: 17px;
}

.course .cate-list::after {
  content: "";
  display: block;
  clear: both;
}

.course .cate-list li {
  float: left;
  font-size: 16px;
  padding: 6px 15px;
  line-height: 16px;
  margin-left: 14px;
  position: relative;
  transition: all .3s ease;
  cursor: pointer;
  color: #4a4a4a;
  border: 1px solid transparent; /* transparent 透明 */
}

.course .cate-list .title {
  color: #888;
  margin-left: 0;
  letter-spacing: .36px;
  padding: 0;
  line-height: 28px;
}

.course .cate-list .this {
  color: #ffc210;
  border: 1px solid #ffc210 !important;
  border-radius: 30px;
}

.course .ordering::after {
  content: "";
  display: block;
  clear: both;
}

.course .ordering ul {
  float: left;
}

.course .ordering ul::after {
  content: "";
  display: block;
  clear: both;
}

.course .ordering .condition-result {
  float: right;
  font-size: 14px;
  color: #9b9b9b;
  line-height: 28px;
}

.course .ordering ul li {
  float: left;
  padding: 6px 15px;
  line-height: 16px;
  margin-left: 14px;
  position: relative;
  transition: all .3s ease;
  cursor: pointer;
  color: #4a4a4a;
}

.course .ordering .title {
  font-size: 16px;
  color: #888;
  letter-spacing: .36px;
  margin-left: 0;
  padding: 0;
  line-height: 28px;
}

.course .ordering .this {
  color: #ffc210;
}

.course .ordering .price {
  position: relative;
}

.course .ordering .price::before,
.course .ordering .price::after {
  cursor: pointer;
  content: "";
  display: block;
  width: 0px;
  height: 0px;
  border: 5px solid transparent;
  position: absolute;
  right: 0;
}

.course .ordering .price::before {
  border-bottom: 5px solid #aaa;
  margin-bottom: 2px;
  top: 2px;
}

.course .ordering .price::after {
  border-top: 5px solid #aaa;
  bottom: 2px;
}

.course .course-item:hover {
  box-shadow: 4px 6px 16px rgba(0, 0, 0, .5);
}

.course .course-item {
  width: 1100px;
  background: #fff;
  padding: 20px 30px 20px 20px;
  margin-bottom: 35px;
  border-radius: 2px;
  cursor: pointer;
  box-shadow: 2px 3px 16px rgba(0, 0, 0, .1);
  /* css3.0 过渡动画 hover 事件操作 */
  transition: all .2s ease;
}

.course .course-item::after {
  content: "";
  display: block;
  clear: both;
}

/* 顶级元素 父级元素  当前元素{} */
.course .course-item .course-image {
  float: left;
  width: 423px;
  height: 210px;
  margin-right: 30px;
}

.course .course-item .course-image img {
  width: 100%;
}

.course .course-item .course-info {
  float: left;
  width: 596px;
}

.course-item .course-info h3 {
  font-size: 26px;
  color: #333;
  font-weight: normal;
  margin-bottom: 8px;
}

.course-item .course-info h3 span {
  font-size: 14px;
  color: #9b9b9b;
  float: right;
  margin-top: 14px;
}

.course-item .course-info h3 span img {
  width: 11px;
  height: auto;
  margin-right: 7px;
}

.course-item .course-info .teather-info {
  font-size: 14px;
  color: #9b9b9b;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid #333;
  border-bottom-color: rgba(51, 51, 51, .05);
}

.course-item .course-info .teather-info span {
  float: right;
}

.course-item .lesson-list::after {
  content: "";
  display: block;
  clear: both;
}

.course-item .lesson-list li {
  float: left;
  width: 44%;
  font-size: 14px;
  color: #666;
  padding-left: 22px;
  /* background: url("路径") 是否平铺 x轴位置 y轴位置 */
  background: url("/src/assets/img/play-icon-gray.svg") no-repeat left 4px;
  margin-bottom: 15px;
}

.course-item .lesson-list li .lesson-title {
  /* 以下3句,文本内容过多,会自动隐藏,并显示省略符号 */
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  display: inline-block;
  max-width: 200px;
}

.course-item .lesson-list li:hover {
  background-image: url("/src/assets/img/play-icon-yellow.svg");
  color: #ffc210;
}

.course-item .lesson-list li .free {
  width: 34px;
  height: 20px;
  color: #fd7b4d;
  vertical-align: super;
  margin-left: 10px;
  border: 1px solid #fd7b4d;
  border-radius: 2px;
  text-align: center;
  font-size: 13px;
  white-space: nowrap;
}

.course-item .lesson-list li:hover .free {
  color: #ffc210;
  border-color: #ffc210;
}

.course-item .pay-box::after {
  content: "";
  display: block;
  clear: both;
}

.course-item .pay-box .discount-type {
  padding: 6px 10px;
  font-size: 16px;
  color: #fff;
  text-align: center;
  margin-right: 8px;
  background: #fa6240;
  border: 1px solid #fa6240;
  border-radius: 10px 0 10px 0;
  float: left;
}

.course-item .pay-box .discount-price {
  font-size: 24px;
  color: #fa6240;
  float: left;
}

.course-item .pay-box .original-price {
  text-decoration: line-through;
  font-size: 14px;
  color: #9b9b9b;
  margin-left: 10px;
  float: left;
  margin-top: 10px;
}

.course-item .pay-box .buy-now {
  width: 120px;
  height: 38px;
  background: transparent;
  color: #fa6240;
  font-size: 16px;
  border: 1px solid #fd7b4d;
  border-radius: 3px;
  transition: all .2s ease-in-out;
  float: right;
  text-align: center;
  line-height: 38px;
}

.course-item .pay-box .buy-now:hover {
  color: #fff;
  background: #ffc210;
  border: 1px solid #ffc210;
}
</style>


3 课程相关表分析

# 表分析
-课程分类表:id,分类名,继承BaseModel
    	-跟课程表是一对多,一个分类下有很多课程
-课程表(实战课课表)
			-如果一个表:
				-不同课程直接,字段可能不一样
			-多个课程,多个表
				-只写实战课这条线
-章节表:
    	跟课程是一对多
-课时表
    	跟章节是一对多
-老师表
    	-跟课程一对多
        
        
        
# 表的关联关系---》公司中外键都是逻辑外键,不建物理外键
-靠一个东西建立出来的三种关系----》外键
        -一对一 
        -一对多
        -多对多
        
        图书  作者 多对多
        图书表
        id  name   price
        1    xx     33
        2    yy     32
        
        作者
       id  name       addr
        1    多对     上海
        2    大师傅     北京
        
        中间表
        id  book_id   auth_id
        1   1            1
        2   1            2
        3   2            1
    	
      
# 基于对象的跨表查询
正:字段  
反:表名小写(一对一是表名小写,一对多是表名小写_set.all())
-related_name='xxx' 替换表名小写

# 基于双下划线的连表查询
正:字段
反:表名小写
-related_query_name='xxx' 替换表名小写


表模型详见  https://www.cnblogs.com/liuqingzheng/articles/17168938.html

4 课程表数据录入

# 把sql执行
# 把media文件夹下的图片放到对应位置
-- 老师表
INSERT INTO luffy_teacher(id, orders, is_show, is_delete, created_time, updated_time, name, role, title, signature, image, brief) VALUES (1, 1, 1, 0, '2022-07-14 13:44:19.661327', '2022-07-14 13:46:54.246271', 'Alex', 1, '老男孩Python教学总监', '金角大王', 'teacher/alex_icon.png', '老男孩教育CTO & CO-FOUNDER 国内知名PYTHON语言推广者 51CTO学院2016\2017年度最受学员喜爱10大讲师之一 多款开源软件作者 曾任职公安部、飞信、中金公司、NOKIA中国研究院、华尔街英语、ADVENT、汽车之家等公司');

INSERT INTO luffy_teacher(id, orders, is_show, is_delete, created_time, updated_time, name, role, title, signature, image, brief) VALUES (2, 2, 1, 0, '2022-07-14 13:45:25.092902', '2022-07-14 13:45:25.092936', 'Mjj', 0, '前美团前端项目组架构师', NULL, 'teacher/mjj_icon.png', '是马JJ老师, 一个集美貌与才华于一身的男人,搞过几年IOS,又转了前端开发几年,曾就职于美团网任高级前端开发,后来因为不同意王兴(美团老板)的战略布局而出家做老师去了,有丰富的教学经验,开起车来也毫不含糊。一直专注在前端的前沿技术领域。同时,爱好抽烟、喝酒、烫头(锡纸烫)。 我的最爱是前端,因为前端妹子多。');

INSERT INTO luffy_teacher(id, orders, is_show, is_delete, created_time, updated_time, name, role, title, signature, image, brief) VALUES (3, 3, 1, 0, '2022-07-14 13:46:21.997846', '2022-07-14 13:46:21.997880', 'Lyy', 0, '老男孩Linux学科带头人', NULL, 'teacher/lyy_icon.png', 'Linux运维技术专家,老男孩Linux金牌讲师,讲课风趣幽默、深入浅出、声音洪亮到爆炸');


-- 分类表
INSERT INTO luffy_course_category(id, orders, is_show, is_delete, created_time, updated_time, name) VALUES (1, 1, 1, 0, '2022-07-14 13:40:58.690413', '2022-07-14 13:40:58.690477', 'Python');

INSERT INTO luffy_course_category(id, orders, is_show, is_delete, created_time, updated_time, name) VALUES (2, 2, 1, 0, '2022-07-14 13:41:08.249735', '2022-07-14 13:41:08.249817', 'Linux');


-- 课程表
INSERT INTO luffy_course(id, orders, is_show, is_delete, created_time, updated_time, name, course_img, course_type, brief, level, pub_date, period, attachment_path, status, students, sections, pub_sections, price, course_category_id, teacher_id) VALUES (1, 1, 1, 0, '2022-07-14 13:54:33.095201', '2022-07-14 13:54:33.095238', 'Python开发21天入门', 'courses/alex_python.png', 0, 'Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土&&&Python从入门到入土', 0, '2022-07-14', 21, '', 0, 231, 120, 120, 0.00, 1, 1);

INSERT INTO luffy_course(id, orders, is_show, is_delete, created_time, updated_time, name, course_img, course_type, brief, level, pub_date, period, attachment_path, status, students, sections, pub_sections, price, course_category_id, teacher_id) VALUES (2, 2, 1, 0, '2022-07-14 13:56:05.051103', '2022-07-14 13:56:05.051142', 'Python项目实战', 'courses/mjj_python.png', 0, '', 1, '2022-07-14', 30, '', 0, 340, 120, 120, 99.00, 1, 2);

INSERT INTO luffy_course(id, orders, is_show, is_delete, created_time, updated_time, name, course_img, course_type, brief, level, pub_date, period, attachment_path, status, students, sections, pub_sections, price, course_category_id, teacher_id) VALUES (3, 3, 1, 0, '2022-07-14 13:57:21.190053', '2022-07-14 13:57:21.190095', 'Linux系统基础5周入门精讲', 'courses/lyy_linux.png', 0, '', 0, '2022-07-14', 25, '', 0, 219, 100, 100, 39.00, 2, 3);


-- 章节表
INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (1, 1, 1, 0, '2022-07-14 13:58:34.867005', '2022-07-14 14:00:58.276541', 1, '计算机原理', '', '2022-07-14', 1);

INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (2, 2, 1, 0, '2022-07-14 13:58:48.051543', '2022-07-14 14:01:22.024206', 2, '环境搭建', '', '2022-07-14', 1);

INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (3, 3, 1, 0, '2022-07-14 13:59:09.878183', '2022-07-14 14:01:40.048608', 1, '项目创建', '', '2022-07-14', 2);

INSERT INTO luffy_course_chapter(id, orders, is_show, is_delete, created_time, updated_time, chapter, name, summary, pub_date, course_id) VALUES (4, 4, 1, 0, '2022-07-14 13:59:37.448626', '2022-07-14 14:01:58.709652', 1, 'Linux环境创建', '', '2022-07-14', 3);


-- 课时表
INSERT INTO luffy_course_section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (1, 1, 0, '2022-07-14 14:02:33.779098', '2022-07-14 14:02:33.779135', '计算机原理上', 1, 2, NULL, NULL, '2022-07-14 14:02:33.779193', 1, 1);

INSERT INTO luffy_course_section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (2, 1, 0, '2022-07-14 14:02:56.657134', '2022-07-14 14:02:56.657173', '计算机原理下', 2, 2, NULL, NULL, '2022-07-14 14:02:56.657227', 1, 1);

INSERT INTO luffy_course_section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (3, 1, 0, '2022-07-14 14:03:20.493324', '2022-07-14 14:03:52.329394', '环境搭建上', 1, 2, NULL, NULL, '2022-07-14 14:03:20.493420', 0, 2);

INSERT INTO luffy_course_section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (4, 1, 0, '2022-07-14 14:03:36.472742', '2022-07-14 14:03:36.472779', '环境搭建下', 2, 2, NULL, NULL, '2022-07-14 14:03:36.472831', 0, 2);

INSERT INTO luffy_course_section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (5, 1, 0, '2022-07-14 14:04:19.338153', '2022-07-14 14:04:19.338192', 'web项目的创建', 1, 2, NULL, NULL, '2022-07-14 14:04:19.338252', 1, 3);

INSERT INTO luffy_course_section(id, is_show, is_delete, created_time, updated_time, name, orders, section_type, section_link, duration, pub_date, free_trail, chapter_id) VALUES (6, 1, 0, '2022-07-14 14:04:52.895855', '2022-07-14 14:04:52.895890', 'Linux的环境搭建', 1, 2, NULL, NULL, '2022-07-14 14:04:52.895942', 1, 4);

5 课程主页接口

# 不是一个页面发送一个请求,不一定是一个请求把一堆数据全部拿回。


# 课程分类接口

# 查询所有课程接口
-带过滤
-带排序
-带分页

视图类

from .models import CourseCategory
from rest_framework.viewsets import GenericViewSet
from .serializer import CourseCategorySerializer
from utils.common_mixin import CommonListModelMixin 

class CourseCategoryView(GenericViewSet, ListModelMixin):
    # 查询所有
    queryset = CourseCategory.objects.filter(is_delete=False, is_show=True).order_by('orders')
    serializer_class = CourseCategorySerializer

序列化类


class CourseCategorySerializer(serializers.ModelSerializer):
    class Meta:
        model = CourseCategory
        fields = ['id','name']

路由

# 路由分发
urlpatterns = [path('api/v1/course/',include('course.urls')),]


# 分路由
from django.urls import path
from rest_framework.routers import SimpleRouter
router = SimpleRouter()
from .views import CourseCategoryView
router.register('category', CourseCategoryView, 'category')
urlpatterns = [

]
urlpatterns += router.urls

作业

# 验证码登录
-写个接口,访问,返回二维码,开启一个定时器,不停向后端发送请求
-去redis中查,如果有token---》直接带回来,显示登录成功,token保存到本地
-掏出手机,扫描二维码,携带id=1,到后端,给id为1的用户签发token,放到reids中
    

标签:12,14,course,项目,路飞,2022,time,id,07
From: https://www.cnblogs.com/10086upup/p/17523357.html

相关文章

  • 中移物联车联网项目,在 TDengine 3.0 的应用
    小T导读:在中移物联网的智慧出行场景中,需要存储车联网设备的轨迹点,还要支持对车辆轨迹进行查询。为了更好地进行数据处理,他们在2021年上线了TDengine2.0版本的5节点3副本集群。3.0发布后,它的众多特性吸引着中移物联网进行了大版本升级。本文详细分享了中移物联网在3.0......
  • TP项目中使用redis
    1.redis3中通配符*(匹配多个字符),?(匹配单个字符),[](匹配括号内某个字符)2.常用操作\Facade\Redis::setex('SMS:110:randNumber',86400,1111);键名,有效期,键值\Facade\Redis::get($key);\Facade\Redis::del($key);\Facade\Redis::keys('SMS:110:*');搜索符合条件的键值......
  • 理解ASEMI代理海矽美快恢复二极管SFP3012A的性能与应用
    编辑-Z在电子元件领域,快恢复二极管SFP3012A是一种重要的半导体器件,它在电路设计中扮演着至关重要的角色。本文将深入探讨SFP3012A的性能特点和应用领域,帮助读者更好地理解和使用这种二极管。 一、SFP3012A的性能特点 快恢复二极管SFP3012A具有许多优秀的性能特点。首先,它具......
  • ASEMI代理海矽美SFP3012, 快恢复二极管SFP3012参数
    编辑-ZSFP3012参数描述:型号:SFP3012最大反向重复峰值电压VRRM:1200V平均整流正向电流IF:30A反向恢复时间TRR:≤65nS正向峰值浪涌电流IFSM:160×2A工作接点温度TJ:-40~175℃储存温度TSTG:-40~175℃典型热阻RθJC:0.5℃/WVB:1200VIR:0.01mAVF:2.2V  SFP3012特征:超快速切换,实现......
  • oracle 表查询变慢的原因-项目
     1)     abovesqldidfulltablescanitexecuted37timeandtookaround10minDELETEFROMPF_LIQUDATION_DETAILS_EODWHEREPORTFOLIOID=:B2ANDASOFDATE=:B1 WeneedtolookattheindexesforthesePF_*tablesandaddindexessothatwecanreducethe......
  • SFP6012-ASEMI代理MHCHXM(海矽美)二极管SFP6012
    编辑:llSFP6012-ASEMI代理MHCHXM(海矽美)二极管SFP6012型号:SFP6012品牌:MHCHXM(海矽美)封装:TO-247AB恢复时间:≤75ns正向电流:30A反向耐压:1200V芯片个数:双芯片引脚数量:3类型:快恢复二极管特性:快恢复、大电流浪涌电流:300A*2正向压降:2.2V~2.4V封装尺寸:如图工作温度:-40°C~175°CSFP6012特性超......
  • SFP6012-ASEMI代理MHCHXM(海矽美)二极管SFP6012
    编辑:llSFP6012-ASEMI代理MHCHXM(海矽美)二极管SFP6012型号:SFP6012品牌:MHCHXM(海矽美)封装:TO-247AB恢复时间:≤75ns正向电流:30A反向耐压:1200V芯片个数:双芯片引脚数量:3类型:快恢复二极管特性:快恢复、大电流浪涌电流:300A*2正向压降:2.2V~2.4V封装尺寸:如图工作温度:-40°C~175......
  • OGG-02912 Patch 17030189 is required on your Oracle mining database for trail fo
    Therewillbeascript"prvtlmpg.plb"undergghomedirectory[oracle@OGGR2-1ogg]$ls-lrtprvtlmpg.plb-rw-r-----1oracleoinstall9487May272015prvtlmpg.plb[oracle@OGGR2-1ogg]$pwd/ogg[oracle@OGGR2-1ogg]$Logintothedatabaseand......
  • 关于Java RDP协议实现远程桌面连接的开源项目properjavardp
    最近想学一下在Android平台上实现RDP协议远程连接PC,于是在网上找这方面的资料,发现了一个开源的JavaRDP项目,很不错,拿出来和大家分享一下。关于properjavardp的一些说明,可以到这里看看:http://properjavardp.sourceforge.net/ 。1、首先到http://sourceforge.net/projects/properjav......
  • create-vue 创建vue项目
    1.前提环境已经安装16.0或者更高版本的node.js2.创建一个vue项目npminitvue@latest//将会安装并且执行create-vue 注意:npmrundev......