django-vue之信息过滤(过滤课程)
一 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之信息过滤(过滤课程)的更多相关文章
- Vue数组更新及过滤排序
前面的话 Vue为了增加列表渲染的功能,增加了一组观察数组的方法,而且可以显示一个数组的过滤或排序的副本.本文将详细介绍Vue数组更新及过滤排序 变异方法 Vue 包含一组观察数组的变异方法,它们将会 ...
- django: rest-framework的 分页和过滤
django: rest-framework的 分页和过滤 2018年06月28日 10:09:01 weixin_42359464 阅读数:136 标签: flaskrestframeworkdja ...
- day81:luffy:课程分类页面&课程信息页面&指定分类显示课程信息&分页显示课程信息
目录 1.构建课程前端初始页面 2.course后端的准备工作 3.后端实现课程分类列表接口 4.前端发送请求-获取课程分类信息 5.后端实现课程列表信息的接口 6.前端显示列表课程信息 7.按照指定 ...
- Django+Vue+Nginx+Https域名代理访问
Django+Vue使用Nginx实现Https域名的安全访问 前端 VUE 前端访问自身域名: https://demo.com,后序使用 Nginx 代理至后端 直接访问后端https:api会无 ...
- 解决Django+Vue前后端分离的跨域问题及关闭csrf验证
前后端分离难免要接触到跨域问题,跨域的相关知识请参:跨域问题,解决之道 在Django和Vue前后端分离的时候也会遇到跨域的问题,因为刚刚接触Django还不太了解,今天花了好长的时间,查阅了 ...
- nginx + uwsgi 部署 Django+Vue项目
nginx + uwsgi 部署 Django+Vue项目 windows 本地 DNS 解析 文件路径 C:\Windows\System32\drivers\etc 单机本地测试运行方式,调用dj ...
- Django+vue在腾讯云上搭建前后端分离项目
最近打算用Django+vue搭建一个个人主站,在此记录一下搭建项目的整个过程. 一 开发环境: 腾讯云Centos 7 Python 3.7 Django ...
- Vue 电影信息影评(豆瓣,猫眼)
Vue电影信息影评网站 此网站是我的毕业设计,题目是"基于HTML5的电影信息汇总弄网站",由于最近在看Vue.js,所以就想用Vue.js来构建一个前端网站,这里code就不大篇 ...
- Nginx+uwsgi+django+vue部署项目
购买服务器 # 购买阿里云服务器 # 短期或是测试使用,创建 按量收费 服务器,可以随时删除,删除后不再计费,但要保证账户余额100元以上 连接服务器 1)账号 >: ssh root@39.9 ...
- 海纳百川无所不容,Win10环境下使用Docker容器式部署前后端分离项目Django+Vue.js
原文转载自「刘悦的技术博客」https://v3u.cn/a_id_179 随着现代化产品研发的不断推进,我们会发现,几乎每个产品线都会包含功能各异的服务,而且服务与服务之间存在也会存在着错综复杂的依 ...
随机推荐
- Pgsql特殊排序
对字段值为A,B,C,D的时候进行特殊排序. CASE WHEN aa = 'H' THEN ' WHENaa = 'O' THEN ' ELSE aa END 对数字进行排序,升序,0排到最后面 C ...
- Can't zip RDDs with unequal numbers of partitions
java.lang.IllegalArgumentException: Can't zip RDDs with unequal numbers of partitions //如果两个RDD分区数不同 ...
- EmWebAdmin 生成流程分析
继上一篇的简略的说明 EmWebAdmin 的地址以后下载,生成之后,这一篇讲一下该模板的生成流程 // 上一篇地址: http://www.cnblogs.com/chenfulin5/p/6856 ...
- 理解vertical-align或“如何竖向居中”<转>
在各种技术论坛里经常会有这样的问题提出,“我如何能将这个东西竖向居中?”这个问题通常会跟随着这样一句话,“我使用了 vertical-align:middle,但是不管用! ” 这个问题其实有三个层面 ...
- Differential Geometry之第六章平面曲线的整体性质
第六章.平面曲线的整体性质 1.平面的闭曲线 1.1.切线的旋转指数定理 1.2.等周不等式与圆的几何特性 ,其中 2.平面的凸曲线 支撑函数: 2.1.Minkowski问题 2.2.四顶点定理
- python 人脸识别
"""Performs face alignment and calculates L2 distance between the embeddings of image ...
- Win10下安装MySQL总卡在write configuration的解决办法
先说结论 删除 C:\ProgramData 下的MySQL文件夹!!! 折腾过程 反复安装卸载,安装版.绿色版,都不行,清理注册表,清理安装文件夹,还是不行!!! 最后找到并删除 C:\Prog ...
- 越大优先级越高,优先级越高被OS选中的可能性就越大
进程的休眠:Thread sleep(1000);//括号中以毫秒为单位 当main()运行完毕,即使在结束时时间片还没有用完,CPU也放弃此时间片,继续运行其他程序. Try{Thread.slee ...
- 故如果要比较两个字符串是否相同可以对a调用equal
故如果要比较两个字符串是否相同(而不是他们的地址是否相同).可以对a调用equal: System.out.println(a.equal(b)); equal用来比较两个对象中字符串的顺序. a.e ...
- php -- 用文本来存储内容,file_put_contents,serialize,unserialize
根据存储的内容来划分 字符串: file_put_contents :将一个字符串写入文件 语法:int file_put_contents ( string $filename , mixed $d ...