from django.conf.urls import url
from django.contrib import admin
from blog.views import index,student,student1,video urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index/', index),
url(r'^student/',student),
url(r'^student1/',student1),
url(r'^video-(?P<direction_id>\d+)-(?P<class_id>\d+)-(?P<level_id>\d+).html',video),
]

simpletag

#!/usr/bin/env python
# -*- coding:utf-8 -*-
from django import template
from django.utils.safestring import mark_safe register = template.Library() @register.simple_tag
def my_simple_time(v1, v2, v3):
return v1 + v2 + v3 @register.simple_tag
def detail1(item,counter,allcount,remainder):
temp = '''
<div style="width: 205px;">
<img style="width: 205px;height: 220px" src="/%s">
<p>%s</p>
<p>%s</p>
<p>%s</p>
<p>%s</p>
</div>
'''
if counter%allcount ==remainder:
temp = temp % (
item['student__pic'],
item['student__name'],
item['student__salary'],
item['student__company'],
item['litter_thanks'],
)
return mark_safe(temp)
else:
return '' @register.filter
def detail2(value,args):
allcount,remainder = args.split(',')
allcount = int(allcount)
remainder = int(remainder)
if value%allcount ==remainder:
return True
return False @register.simple_tag
def action(current_url,item,index):
url_list = current_url.split('-')
if index ==3:
if str(item['id']) ==url_list[index].split('.')[0]:
temp = "<a href=%s class='active'>%s</a>"
else:
temp = '<a href=%s>%s</a>'
url_list[index] = str(item['id'])+'.html'
else:
if str(item['id']) == url_list[index]:
temp = "<a href=%s class='active'>%s</a>"
else:
temp = '<a href=%s>%s</a>'
url_list[index] = str(item['id'])
url_str = '-'.join(url_list)
temp = temp%(url_str,item['name'])
return mark_safe(temp) @register.simple_tag
def action_all(current_url,index):
url_list = current_url.split('-')
if index ==3:
if url_list[index]=='0.html':
temp = "<a href=%s class='active'>全部</a>"
else:
temp = "<a href=%s >全部</a>"
url_list[index]= '0.html'
else:
if url_list[index] == '':
temp = "<a href=%s class='active'>全部</a>"
else:
temp = "<a href=%s >全部</a>"
url_list[index] = '' href = '-'.join(url_list)
temp = temp % (href,)
return mark_safe(temp)

admin

from django.contrib import admin
from blog import models
# Register your models here.
admin.site.register(models.BxSlider)
admin.site.register(models.Classification)
#admin.site.register(models.Course)
admin.site.register(models.Direction)
#admin.site.register(models.Notice)
#admin.site.register(models.Recruit)
admin.site.register(models.Student)
admin.site.register(models.Studentdetail)
admin.site.register(models.Video)

models

from django.db import models

# Create your models here.
class BxSlider (models.Model):
status_choice = (
(0, '下线'),
(1, '上线'),
)
status = models.IntegerField(choices=status_choice,default=1)
name = models.CharField(max_length=32,db_index=True,unique=True)
img = models.ImageField(upload_to='./static/imgs/focus/')
href = models.CharField(max_length=256)
creat_date = models.DateTimeField(auto_now_add=True) class Meta:
db_table = 'BxSlider'
verbose_name_plural = '首页轮播'
def __str__(self):
return self.name class Notice(models.Model):
status_choice=(
(0,'不显示'),
(1,'显示'),
)
status = models.IntegerField(verbose_name='状态',choices=status_choice,default=0)
weight = models.IntegerField(verbose_name='权重(按从大到小排列)',default=0)
title = models.CharField(verbose_name='标题',max_length=32)
content = models.CharField(verbose_name='简介',max_length=256)
detail = models.TextField(verbose_name='公告详细',null=True,blank=True)
class Meta:
db_table='Notice'
verbose_name_plural='最新公告(开班信息等)'
def __str__(self):
return self.title class Course(models.Model):
status_choice=(
(0,'下线'),
(1,'上线'),
)
status = models.IntegerField(verbose_name='状态',choices=status_choice,default=1)
weight = models.IntegerField(verbose_name='权重(按从大到小排列)',default=0)
icon = models.ImageField(verbose_name='图标',upload_to='./static/imgs/icon',null=True,blank=True)
name = models.CharField(verbose_name='名称',max_length=32,db_index=True,unique=True)
summary = models.CharField(verbose_name='简介',max_length=46,default='summary') class Meta:
db_table='Course'
verbose_name_plural='课程'
def __str__(self):
return self.name class Recruit(models.Model):
status_choice=(
(0,'已过期'),
(1,'招聘中'),
)
status = models.IntegerField(verbose_name='状态',choices=status_choice,default=1)
weight = models.IntegerField(verbose_name='权重(按从大到小排列)',default=0)
title = models.CharField(verbose_name='标题',max_length=32)
salary = models.CharField(verbose_name='薪水',max_length=25)
conpany = models.CharField(max_length=20)
detail = models.TextField(verbose_name='详细')
deadline=models.DateField()
class Meta:
db_table='Recruit'
verbose_name_plural='招聘信息'
def __str__(self):
return self.title class Student(models.Model):
status_choice = (
(0, '不显示'),
(1, '显示'),
)
status = models.IntegerField(verbose_name='状态',choices=status_choice,default=0)
weight = models.IntegerField(verbose_name='权重(按从大到小排列)',default=0)
name = models.CharField(verbose_name='名称',max_length=32,db_index=True,unique=True)
pic = models.ImageField(verbose_name='头像',upload_to='./static/imgs/stu_pic/',null=True)
company = models.CharField(verbose_name='就业单位', max_length=32)
salary = models.CharField(verbose_name='薪水', max_length=25)
class Meta:
db_table='Student'
verbose_name_plural='学生信息'
def __str__(self):
return self.name class Studentdetail(models.Model):
student = models.OneToOneField('Student')
weight = models.IntegerField(verbose_name='权重(按从大到小排列)',default=0)
litter_thanks= models.CharField(verbose_name='感谢信',max_length=256)
class Meta:
db_table='Studentdetail'
verbose_name_plural='学生更多信息'
def __str__(self):
return self.student.name class Classification(models.Model):
weight = models.IntegerField(verbose_name='权重(按从大到小排列)', default=0)
name = models.CharField(verbose_name='名称', max_length=32)
class Meta:
db_table='Classification'
verbose_name_plural='课程视频分类'
def __str__(self):
return self.name class Video(models.Model):
status_choice=(
(0,'下线'),
(1,'上线'),
)
level_choice=(
(1,'初级'),
(2,'中级'),
(3,'高级'),
)
status = models.IntegerField(verbose_name='状态',choices=status_choice,default=1)
level = models.IntegerField(verbose_name='状态', choices=level_choice, default=1)
weight = models.IntegerField(verbose_name='权重(按从大到小排列)',default=0)
img = models.ImageField(verbose_name='图像',upload_to='./static/imgs/video/',null=True,blank=True)
name = models.CharField(verbose_name='名称',max_length=32,db_index=True,unique=True)
summary = models.CharField(verbose_name='简介',max_length=46,default='summary')
title = models.CharField(verbose_name='标题', max_length=32)
href = models.CharField(max_length=256)
creat_date = models.DateTimeField(auto_now_add=True)
classification = models.ForeignKey('Classification',null=True,blank=True)
class Meta:
db_table='Video'
verbose_name_plural='课程视频'
def __str__(self):
return self.title class Direction(models.Model):
weight = models.IntegerField(verbose_name='权重(按从大到小排列)', default=0)
name = models.CharField(verbose_name='名称', max_length=32)
classification = models.ManyToManyField('Classification')
class Meta:
db_table='Direction'
verbose_name_plural='视频方向'
def __str__(self):
return self.name

views

from django.shortcuts import render,HttpResponse
from blog import models
import json
# Create your views here.
def index(request):
queryset_dict = models.BxSlider.objects.filter(status=1).values('img','href','name')
return render(request,'index.html',{'queryset_dict':queryset_dict}) def student(request):
#student
# studentdetail
detail_list = models.Studentdetail.objects.filter(student__status=1).values('litter_thanks','student__name','student__company','student__salary','student__pic')
print(detail_list)
return render(request,'student.html',{'detail_list':detail_list}) def student1(request):
if request.method =='POST':
detail_list = models.Studentdetail.objects.filter(student__status=1).values('litter_thanks', 'student__name',
'student__company',
'student__salary', 'student__pic')
detail_list = list(detail_list)
return HttpResponse(json.dumps(detail_list))
#student
# studentdetail
#detail_list = models.Studentdetail.objects.filter(student__status=1).values('litter_thanks','student__name','student__company','student__salary','student__pic') return render(request,'student1.html') def video(request,*args,**kwargs):
current_url = request.path
q = {}
q['status'] = 1
drection_list = models.Direction.objects.all().values('id','name')
if kwargs.get('direction_id')=='':
classifi_list = models.Classification.objects.all().values('id', 'name')
if kwargs.get('class_id')=='':
pass
else:
q['classification_id__in'] = [kwargs.get('class_id'),]
else:
if kwargs.get('class_id')=='':
obj = models.Direction.objects.get(id = int(kwargs.get('direction_id')))
classifi_list = obj.classification.all().values('id', 'name')
id_list = list(map(lambda x: x['id'], classifi_list))
q['classification_id__in']=id_list
else:
obj = models.Direction.objects.get(id=int(kwargs.get('direction_id')))
classifi_list = obj.classification.all().values('id', 'name')
id_list = list(map(lambda x:x['id'],classifi_list))
q['classification_id__in'] = [kwargs.get('class_id'),]
if int(kwargs.get('class_id')) in id_list:
pass
else:
url_part_list = current_url.split('-')
url_part_list['']=''
current_url = '-'.join(url_part_list)
level_id = int(kwargs.get('level_id'))
if level_id ==0:
pass
else:
q['level']= level_id
video_list = models.Video.objects.filter(**q).values('title','summary','img','href') ret = map(lambda x:{'id':x[0],'name':x[1]},models.Video.level_choice)
leve_list =list(ret)
print(kwargs) return render(request, 'video.html',{'drection_list':drection_list,
'classifi_list':classifi_list,
'leve_list':leve_list,
'current_url':current_url,
'video_list':video_list})

video.html

{% load xxx %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
a{
padding: 5px;
display: inline-block;
}
.active{
background-color: orange;
color: white;
}
.item{
display: inline-block;
width: 205px;
height: 240px;
}
.item img{
border: 0;
width:205px;
height:240px;
}
</style>
</head>
<body>
<h3>选择:</h3>
<hr/>
<div>
{% action_all current_url 1 %}
{% for item in drection_list %}
{% action current_url item 1 %}
{% endfor %}
</div>
<div>
{% action_all current_url 2 %}
{% for item in classifi_list %}
{% action current_url item 2 %}
{% endfor %}
</div>
<div>
{% action_all current_url 3 %}
{% for item in leve_list %}
{% action current_url item 3 %}
{% endfor %}
</div>
<h3>视频:</h3>
<hr/>
{% for item in video_list %}
<a class="item" href="{{ item.href }}">
<img src="/{{ item.img }}"/>
<p>{{ item.title }}</p>
<p>{{ item.summary }}</p>
</a>
{% endfor %}
</body>
</html>

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link href="/static/plugins/bxslider/jquery.bxslider.css" rel="stylesheet"/>
</head>
<body>
<ul class="bxslider">
{% for item in queryset_dict %}
<li>
<a href="{{ item.href }}">
<img src="/{{ item.img }}" alt="{{ item.name }}">
</a>
</li>
{% endfor %}
</ul>
<script src="/static/js/jquery-3.2.1.min.js"></script>
<script src="/static/plugins/bxslider/jquery.bxslider.min.js"></script>
<script>
$(document).ready(function(){
$('.bxslider').bxSlider();
});
</script>
</body>
</html>

student

{% load xxx %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.clearfix:after{
content: '.';
visibility:hidden;
height: 0;
clear: both;
display: block;
}
</style>
</head>
<body> <div style="margin: 0 auto;width: 980px" class="clearfix">
<div style="width: 245px;float:left;">
{% for item in detail_list %}
{% detail1 item forloop.counter 4 1 %}
{% endfor %}
</div>
<div style="width: 245px;float:left;">
{% for item in detail_list %}
{% detail1 item forloop.counter 4 2 %}
{% endfor %}
</div>
<div style="width: 245px;float:left;">
{% for item in detail_list %}
{% detail1 item forloop.counter 4 3 %}
{% endfor %}
</div>
<div style="width: 245px;float:left;">
{% for item in detail_list %}
{% if forloop.counter|detail2:'4,0' %}
<div style="width: 205px;">
<img style="width: 205px;height: 220px" src="/{{ item.student__pic }}">
<p>{{ item.student__name }}</p>
<p>{{ item.student__salary }}</p>
<p>{{ item.student__company }}</p>
<p>{{ item.litter_thanks }}</p>
</div>
{% endif %}
{% endfor %}
</div>
</div> </body>
</html>

Django 分类标签查找的更多相关文章

  1. Django 反向查找(related_name)

    先定义两个模型,一个是A,一个是B,是一对多的类型 class A(models.Model): name= models.CharField('名称', max_length=32) class B ...

  2. django 模版查找路径

    路径的配置,模版上下文的配置等.模版路径可以在两个地方配置. 1.'DIRS':这是一个列表,在这个列表中可以存放所有的模版路径,以后在视图中使用render或者render_to_string渲染模 ...

  3. django xadmin查找当前用户所在组

    self.request.user:获取当前登录用户用户名 qs = Group.objects.get(user=self.request.user)获取当前登录用户所在组qs.name 获取当前登 ...

  4. “全能”选手—Django 1.10文档中文版Part3

    Django 1.10官方文档的入门教程已经翻译完毕,后续的部分将不会按照顺序进行翻译,而是挑重点的先翻译. 有兴趣的可以关注我的博客. 第一部分传送门 第二部分传送门 第四部分传送门 3.2 模型和 ...

  5. python Django教程 之模板渲染、循环、条件判断、常用的标签、过滤器

    python3.5 manage.py runserver python Django教程 之模板渲染.循环.条件判断.常用的标签.过滤器 一.Django模板渲染模板 1. 创建一个 zqxt_tm ...

  6. 循序渐进Python3(十二) --2--  web框架之django简单实现oracle数据库操作

    在 Django 中构建 Oracle 数据库支持的 Web 应用程序 了解如何配置 Django 以便与 Oracle 数据库交互,并使用 ORM 进行数据库连接.             产能在软 ...

  7. 跟我一起Django - 01 安装和初始化

    跟我一起Django - 01 安装和初始化 python环境 C:\Python27\Lib\site-packages>python --versionPython 2.7.5 安装setu ...

  8. django 2

    创建一个管理员用户 首先,我们需要创建一个用户可以登录到管理网站. 运行 下面的命令: $ python manage.py createsuperuser 输入你想要的用户名,按回车. Userna ...

  9. Django搭建博客后台

    转载自:http://sanwen8.cn/p/1cboypN.html 首先创建项目和blog应用: 在cmd命令行下,输入: django-admin.py startproject myblog ...

随机推荐

  1. 【BZOJ1007】水平可见直线(单调栈)

    [BZOJ1007]水平可见直线(单调栈) 题解 Description 在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为 可见的 ...

  2. 【BZOJ2330】【SDOI2012】糖果(差分约束,SPFA)

    [BZOJ2330][SDOI2012]糖果 题面 题目描述 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一些要 ...

  3. 【NOIP2014】解方程(枚举)

    题面 题目描述 已知多项式方程: a0+a1x+a2x^2+..+anx^n=0 求这个方程在[1, m ] 内的整数解(n 和m 均为正整数) 输入格式 输入共n + 2 行. 第一行包含2 个整数 ...

  4. [BZOJ3110][ZJOI2013]K大数查询(整体二分)

    BZOJ Luogu sol 整体二分,其实很简单的啦. 对所有询问二分一个答案mid,把所有修改操作中数字大于mid的做一个区间覆盖(区间加1) 查询就是区间查询 然后左右分一分即可 注意是第k大 ...

  5. 平面图转对偶图(Bzoj1001:狼抓兔子)

    如果只会用最小割做这道题那就太菜辣 引入 来自某学长 平面图:在平面上边不相交的图(边可以绕着画) 那么平面图的边与边就围成了许多个区域(这与你画图的方式有关) 定义对偶图:把相邻的两个区域连上边,形 ...

  6. 改数据库编码latin1为utf8

    因为建数据库的时候没有选utf8,所以默认是latin1 在网上查了好多资料 ,试了很多种方法,都不奏效,有用的一个竟然要一列一列的改, 最后在评论里发现了这个,抱着试一试的心态竟然成功改过来了,在这 ...

  7. mariadb 压缩包gz安装方式

    1.解压安装包tar -zxvf mariadb-5.5.56-linux-x86_64.tar.gz 2.cd support-filescp my-small.cnf /etc/my.cnf 2. ...

  8. 面向对象设计模式_生成器模式详解(Builder Pattern)

    首先提出一个很容易想到应用场景: 手机的生产过程:手机有非常多的子件(部件),成千上万,不同品牌的手机的生产过程都是复杂而有所区别的,相同品牌的手机在设计上也因客户需求多样化,大到型号,小到颜色,是否 ...

  9. leaflet渲染mapbox gl的矢量数据

    准备条件 1.mapbox-gl.js mapbox-gl.css 2.leaflet-mapbox-gl.js https://github.com/mapbox/mapbox-gl-leaflet ...

  10. centos7服务的管理

    centos7上服务管理  author:headsen chen     2017-10-16  16:03:53       1,启动服务(每条都可以) systemctl start httpd ...