我想按类别过滤发送到服务器的帖子:
/?category=IT
但是当我加载此页面时,我想通过GET方法发送下一个参数,例如:
/?category=IT&nav=next
但是该怎么做?如何再次发送类别而不点击它?
当前我的代码如下:
def post_list(request):
categories = Category.objects.order_by('name')
if request.method == 'GET':
if 'category' in request.GET.keys():
posts = Post.objects.order_by('-created').\
filter(category=Category.objects.filter(name=request.GET['category']).first())
else:
posts = Post.objects.order_by('-created')
if 'nav' in request.GET.keys():
if request.GET['nav'] == 'older':
pass
elif request.GET['nav'] == 'newer':
pass
return render(request, 'blog/post_list.html', {'newest': posts[0], 'posts': posts[1:],
'categories': categories})