一对多组合查询/搜索
技术要点:
template
1、使用url携带参数,如 http://www.xxx.com/0-0-0-0-0.HTML
2、通过伪造静态页面路径,增加被搜索引擎收录
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,
'kwargs':kwargs,
'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>
以上是内存溢出为你收集整理的Djnago组合查询和瀑布流全部内容,希望文章能够帮你解决Djnago组合查询和瀑布流所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)