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. Theano环境搭建/安装

    关键词:theano安装,搭建theano环境, python, 深度学习 因为需要安装theano,结果发现这又是一个难以安装的python包-虽然网上教程不少,然而鱼龙混杂,试验了各种方法流程,最 ...

  2. I/HwPointEventFilter: do not support AFT because of no config

    I/HwPointEventFilter: do not support AFT because of no config 这是华为对系统做了修改,默认不打印日志,要改配置 在拨号界面输入:以下进入工 ...

  3. 【BZOJ1010】【HNOI2008】玩具装箱(斜率优化,动态规划)

    [BZOJ1010][HNOI2008]玩具装箱 题面 题目描述 P教授要去看奥运,但是他舍不下他的玩具,于是他决定把所有的玩具运到北京.他使用自己的压缩器进行压缩,其可以将任意物品变成一堆,再放到一 ...

  4. c#抽取pdf文档标题(1)

    首先看看我的项目结构: 从上面的结果图中,我们可以看出,主要用了两个库:itextsharp.dll 和 pdfbox-1.8.9.dll,dll文件夹存放引用的库,handles文件夹存放抽取的处理 ...

  5. 大三小学期 Android开发的一些经验

    1.同一个TextView几种颜色的设置: build=(TextView)findViewById(R.id.building); SpannableStringBuilder style = ne ...

  6. Java Web day01

    1.配置环境 Eclipse版本:Mars.2 Release (4.5.2) jdk版本: 配置Eclipse (1)更改编码 工作空间 jsp页面编码 (2)更改背景颜色及字体大小 (3)安装jr ...

  7. WordPress菜单“显示选项”无法显示的解决办法

    比较新版本的WordPress会出现点击“外观”——“菜单”右上角的“显示选项”无法打开的问题,而老版本的就没有这个问题,后台的其他页面中的这个 功能都可以正常使用,看来问题是因为中文版WordPre ...

  8. 走近webpack(1)--多入口及devServer的使用

    上一篇文章留下了一些问题,如果你没看过上一篇文章,可以在我的博客里查找,或者直接从这篇文章开始也是没问题的. const path = require('path'); module.exports= ...

  9. Redis+Restful 构造序列号和压力测试【原创】

    [本人原创],欢迎交流和分享技术,转载请附上如下内容:如果你觉得这篇文章对你有帮助,请记得帮我点赞, 谢谢!作者:kevin[转自]http://www.cnblogs.com/itshare/ 很多 ...

  10. Vue解析一之挂载全局变量与方法

    1.在mian.js里面进行Vue对象的原型连的挂载Vue.prototype.$ajax = Ajax; 2.使用Mixin: VuVue.mixin({ data(){ return { Host ...