技术要点:
template
1、使用url携带参数,如 http://www.xxx.com/0-0-0-0-0.html
views
1. 通过路由分发获取指定参数
url(r'^video-(?P<classification_id>(\d+))-(?P<level_id>(\d+)).html$',views.video),
2. 使用**进行多个条件查询
代码示例:
------------------views.py------------------
from django.shortcuts import render
from app01 import models
def video(request,*args,**kwargs):
condition = {
# 'level_id': 0,
# 'classification_id': 0,
}
for k,v in kwargs.items():
temp = int(v)
kwargs[k] = temp
if temp:
condition[k] = temp
class_list = models.Classification.objects.all()
level_list = models.Level.objects.all()
video_list = models.Video.objects.filter(**condition)
return render(
request,
'video.html',
{
'class_list':class_list,
'level_list':level_list,
'video_list':video_list,
}
)
video.html
<!DOCTYPE html>
<html>
<head>
<Meta charset="UTF-8">
<title>Title</title>
<style>
.condition a{
display: inline-block;
padding: 5px 8px;
border: 1px solid #dddddd;
}
.condition a.active{
background-color: coral;
color: white;
}
</style>
</head>
<body>
<div>
<h1>筛选</h1>
<div>
{% if kwargs.classification_id == 0 %}
<a href="/video-0-{{ kwargs.level_id }}.html">全部</a>
{% else %}
<a href="/video-0-{{ kwargs.level_id }}.html">全部</a>
{% endif %}
{% for item in class_list %}
{% if item.id == kwargs.classification_id %}
<a href="/video-{{ item.id }}-{{ kwargs.level_id }}.html">{{ item.name }}</a>
{% else %}
<a href="/video-{{ item.id }}-{{ kwargs.level_id }}.html">{{ item.name }}</a>
{% endif %}
{% endfor %}
</div>
<div>
<a href="/video-{{ kwargs.classification_id }}-0.html">全部</a>
{% for item in level_list %}
{% if item.id == kwargs.level_id %}
<a href="/video-{{ kwargs.classification_id }}-{{ item.id }}.html">{{ item.title }}</a>
{% else %}
<a href="/video-{{ kwargs.classification_id }}-{{ item.id }}.html">{{ item.title }}</a>
{% endif %}
{% endfor %}
</div>
</div>
<div>
<h1>结果</h1>
<div>
{% for row in video_list %}
<div>{{ row.title }}</div>
{% endfor %}
</div>
</div>
</body>
</html>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。