一  vue前端代码

实现的内容,通过对课程的分类,在每个不同的课程分类下显示相应的内容
<template>
<div class="course">
<h1>我是课程</h1>
<el-tabs type="border-card">
<el-tab-pane v-for="ca in course_category">
<span slot="label" @click="init(ca.id)"> {{ca.name}}</span>
<el-row>
<el-col :span="8" v-for="course in courses">
<el-card :body-style="{ padding: '0px' }">
<img :src='course.course_img.course_img' class="image">
<div style="padding: 14px;">
<span>{{course.name}}</span>
<div class="bottom clearfix">
<time class="time">{{ currentDate }}</time>
<el-button type="text" class="button">
<router-link :to="{'name':'courseDetail','params':{'id':course.id}}">详情
</router-link>
</el-button>
</div>
</div>
</el-card>
</el-col>
</el-row>
</el-tab-pane>
</el-tabs> </div>
</template> <script>
export default {
data: function () {
return {
courses: [],
currentDate: new Date(),
course_category: [{'name': '全部', 'id': 0},{'name': 'django', 'id': 1}, {'name': 'linux', 'id': 2}, {'name': 'go', 'id': 3}]
}
},
methods: {
init: function (category=0) {
let _this = this;
this.$http.request({
url: this.$url + 'course/'+'?sub_category='+category,
method: 'get'
}).then(function (response) {
console.log(response.data);
_this.courses = response.data.data })
}
},
mounted: function () {
this.init()
} } </script> <style>
.time {
font-size: 13px;
color: #999;
} .bottom {
margin-top: 13px;
line-height: 12px;
} .button {
padding: 0;
float: right;
} .image {
width: 100%;
display: block;
} .clearfix:before,
.clearfix:after {
display: table;
content: "";
} .clearfix:after {
clear: both
}
</style>
序列化
class CourseCategorySerializer(serializers.ModelSerializer):
class Meta:
model = models.CourseDetail
fields = '__all__' course_name = serializers.CharField(source='course.name')
recommend_courses = serializers.SerializerMethodField() def get_recommend_courses(self, obj):
return [{'id': course.pk, 'name': course.name} for course in obj.recommend_courses.all()]
后台代码
from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.response import Response
from app01 import models
from app01.utils.commonUtils import MyResponse
from app01.mySer import CourseSerializer, CourseDetailSerializer
from rest_framework.viewsets import ViewSetMixin from django.core.exceptions import ObjectDoesNotExist
from django.conf import settings from rest_framework.pagination import LimitOffsetPagination # Create your views here. class Course(ViewSetMixin, APIView):
def get_course(self, request, *args, **kwargs): response = MyResponse()
param = request.GET.get('sub_category', None)
print(param)
# course_list = models.Course.objects.all()
# 加分页器
# page = LimitOffsetPagination()
# page.default_limit=2
# page.max_limit=3
# page_list = page.paginate_queryset(course_list,request,self)
course_list = models.Course.objects.all()
param = int(param)
if param: if param == 0:
course_list = models.Course.objects.all()
else:
course_list = models.Course.objects.filter(category_id=param).all() course_ser = CourseSerializer(instance=course_list, many=True)
response.msg = '查询成功'
response.data = course_ser.data
print(response.get_dic) return Response(response.get_dic)

django-vue之信息过滤(过滤课程)的更多相关文章

  1. Vue数组更新及过滤排序

    前面的话 Vue为了增加列表渲染的功能,增加了一组观察数组的方法,而且可以显示一个数组的过滤或排序的副本.本文将详细介绍Vue数组更新及过滤排序 变异方法 Vue 包含一组观察数组的变异方法,它们将会 ...

  2. django: rest-framework的 分页和过滤

    django: rest-framework的 分页和过滤 2018年06月28日 10:09:01 weixin_42359464 阅读数:136 标签: flaskrestframeworkdja ...

  3. day81:luffy:课程分类页面&课程信息页面&指定分类显示课程信息&分页显示课程信息

    目录 1.构建课程前端初始页面 2.course后端的准备工作 3.后端实现课程分类列表接口 4.前端发送请求-获取课程分类信息 5.后端实现课程列表信息的接口 6.前端显示列表课程信息 7.按照指定 ...

  4. Django+Vue+Nginx+Https域名代理访问

    Django+Vue使用Nginx实现Https域名的安全访问 前端 VUE 前端访问自身域名: https://demo.com,后序使用 Nginx 代理至后端 直接访问后端https:api会无 ...

  5. 解决Django+Vue前后端分离的跨域问题及关闭csrf验证

      前后端分离难免要接触到跨域问题,跨域的相关知识请参:跨域问题,解决之道   在Django和Vue前后端分离的时候也会遇到跨域的问题,因为刚刚接触Django还不太了解,今天花了好长的时间,查阅了 ...

  6. nginx + uwsgi 部署 Django+Vue项目

    nginx + uwsgi 部署 Django+Vue项目 windows 本地 DNS 解析 文件路径 C:\Windows\System32\drivers\etc 单机本地测试运行方式,调用dj ...

  7. Django+vue在腾讯云上搭建前后端分离项目

    最近打算用Django+vue搭建一个个人主站,在此记录一下搭建项目的整个过程. 一 开发环境: 腾讯云Centos     7 Python                3.7 Django    ...

  8. Vue 电影信息影评(豆瓣,猫眼)

    Vue电影信息影评网站 此网站是我的毕业设计,题目是"基于HTML5的电影信息汇总弄网站",由于最近在看Vue.js,所以就想用Vue.js来构建一个前端网站,这里code就不大篇 ...

  9. Nginx+uwsgi+django+vue部署项目

    购买服务器 # 购买阿里云服务器 # 短期或是测试使用,创建 按量收费 服务器,可以随时删除,删除后不再计费,但要保证账户余额100元以上 连接服务器 1)账号 >: ssh root@39.9 ...

  10. 海纳百川无所不容,Win10环境下使用Docker容器式部署前后端分离项目Django+Vue.js

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_179 随着现代化产品研发的不断推进,我们会发现,几乎每个产品线都会包含功能各异的服务,而且服务与服务之间存在也会存在着错综复杂的依 ...

随机推荐

  1. java POi excel 写入大批量数据

    直接贴代码: package jp.co.misumi.mdm.batch.common.jobrunner; import java.io.File; import java.io.FileNotF ...

  2. C语言 · 三角形面积

     算法提高 三角形面积   时间限制:1.0s   内存限制:256.0MB      问题描述 由三角形的三边长,求其面积. 提示:由三角形的三边a,b,c求面积可以用如下的公式: s=(a+b+c ...

  3. am335x omap serial 驱动分析

    am335x 自身的 uart 驱动集成在 kernel 的 arch/arm/mach-omap2/ 里面. 文件是 arch/arm/mach-omap2/serial.c // 看到最底部 om ...

  4. C#中利用JQuery实现视频网站的缩略图采集

    最近有朋友想要采集优酷的视频标题和缩略图 (哈哈, 并非商业目的). 找到我帮忙, 考虑到有我刚刚发布的SpiderStudio, 我毫不犹豫的答应了. 首先在网页上视频的基本结构为: div.v - ...

  5. SpringBoot配置使用jsp页面技术

    SpringBoot配置使用jsp页面技术 1.pom配置 package配置必须为war类型 添加依赖 <packaging>war</packaging> <depe ...

  6. Appendix A. Common application properties

    Appendix A. Common application properties Prev  Part X. Appendices  Next URl链接:https://docs.spring.i ...

  7. Go语言入门系列2 基本语法

    get download and install packages and dependencies install = compile and install packages and depend ...

  8. 代码生成利器:IDEA 强大的 Live Templates

    Java 开发过程经常需要编写有固定格式的代码,例如说声明一个私有变量, logger 或者 bean 等等.对于这种小范围的代码生成,我们可以利用 IDEA 提供的 Live Templates 功 ...

  9. boost 互斥体和锁

    1.共享资源是一个自动锁住的房间,互斥体是钥匙,进入房间必须取钥匙,离开房间应该还钥匙.这就对应着互斥体的lock(取钥匙)和unlock(还钥匙). 2.考虑下面的场景:还钥匙的时候出现异常,会发生 ...

  10. 【NOIP模拟题】小象涂色(概率+期望+递推)

    表示数学是个渣... 其实只需要推出每个箱子k次以后的颜色为i的概率就能算出期望了.. 对于区间[l, r]的箱子因为是任意颜色且任意取,所以概率分别为1/c和1/2,那么整体概率就为这两个的乘积.根 ...