一、项目压缩包如下
徐永波_2019.5.25_博客有问题代码.rar
二、项目存在问题简述如下:
通过 年、月向数据库查询数据。无法查询到内容(数据库有两条数据,但是无法正常渲染到页面)

三、涉及到此用途的代码如下:
i定义的方法如下:
class PostArchive(View):
def get(self,request,year=1,month=1):
#获取传递的参数并转换类型
year = int(year)
month = int(month)
if year == 1 and month == 1:
postobj = Post.objects.all().order_by('-publish_time')
else:
postobj = Post.objects.filter(publish_time__year=year,publish_time__month=month)
return render(request,'listpost.html',{'postobj':postobj})
ii渲染页面代码如下
{% extends 'base.html' %}
{% block title %}分类归档页面{% endblock %}
{% block main %}
<div id="main">
<div class="archives">
{% for post in postobj %}
<article class="archive-article archive-type-post">
<div class="archive-article-inner">
<header class="archive-article-header">
<a href="#" class="archive-article-date">
<time>{{ post.publish_time|date:'Y-m' }}</time>
</a>
<h1 itemprop="name">
<a class="archive-article-title" target="_blank" href="/post/{{ post.category_id }}">{{ post.title }}</a>
</h1>
</header>
</div>
</article>
{% empty %}
无记录
{% endfor %}
</div>
</div>
{% endblock %}
iii数据库截图如下:
