我想知道如何才能使Django分页搜索引擎友好,比如:object / 224而不是object?page = 224
此外,任何人都知道为什么它不是默认搜索引擎友好的!?
答案 0 :(得分:2)
调整您的网址:
(r'object/(?P<page>\d+)/$','listing')
然后调整您的视图(此处我使用的是sample from the documentation):
def listing(request,page):
contact_list = Contacts.objects.all()
paginator = Paginator(contact_list, 25) # Show 25 contacts per page
# page = request.GET.get('page') not needed
try:
contacts = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
contacts = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
contacts = paginator.page(paginator.num_pages)
return render_to_response('list.html', {"contacts": contacts})