一、主要逻辑
主要我们在网址端做设置,也就是当用户输入了正确的用户后缀才能跳到,对应的网页,在判断的时候要先去查用户输入的字段是否在数据库中存在
def home(request,**kwargs):
blog = models.Blog.objects.filter(**kwargs).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)')
article_list = models.Article.objects.filter(blog=blog).order_by('-nid').all()
else:
return redirect('/')
return render(request,
'home.html',
{'userinfo':userinfo,
'article_list':article_list,
'blog':blog,
'tag':tag,
'category':Category,
'date_list':date_list,
}
)
网友评论