一、思路
url(r'^(?P<site>\w+)/(?P<condition>((tag)|(data)|(category)))/(?P<val>\w+-*\w*).html$', home.filter),
=
跳转到不同的标签目录的时候,我们在url做手脚,让url整体选择跳转,进行判断应该进入那个分支去提取信息
def filter(request,**kwargs):
site = kwargs['site']
condition = kwargs['condition']
val = kwargs['val']
blog = models.Blog.objects.filter(site=site).first()
if blog:
userinfo = models.UserInfo.objects.filter(blog=blog).first()
tag = models.Tag.objects.filter(blog=blog)
Category = models.Category.objects.filter(blog=blog)
date_list = models.Article.objects.raw(
'select nid, count(nid) as num,strftime("%Y-%m",creat_time) as ctime from repository_article group by strftime("%Y-%m",creat_time)')
if condition == 'tag':
article_list = models.Article.objects.filter(blog=blog,tag=val)
elif condition == 'category':
article_list = models.Article.objects.filter(category_id=val, blog=blog).all()
elif condition == 'data':
article_list = models.Article.objects.filter(blog=blog).extra(
where=['strftime("%%Y-%%m",creat_time)=%s'], params=[val, ]).all()
print(22222,article_list)
else:
article_list=[]
return render(request,
'home.html',
{
'userinfo': userinfo,
'article_list': article_list,
'blog': blog,
'tag': tag,
'category': Category,
'date_list': date_list,
}
)
else:
return redirect('/')
网友评论