所以我试图使用分页来显示某一天可用的所有匹配类,但是按照分页文档,每个页面只返回相同的 10 个结果。我错过了什么/我应该在 urlconf 中有什么?此外,如果我尝试使用分页来显示搜索结果,当我尝试选择下一页时,我会收到错误“视图 search.views.search_classes 没有返回 HttpResponse 对象”。将不胜感激对任何一个或两个示例的任何输入。
#views.py
def upcoming_class_list(request, day):
try:
day = int(day)
except ValueError:
raise Http404()
today = datetime.date.today()
day_x = datetime.date.today() + datetime.timedelta(days=day)
day_x_classes = UpcomingClasses.objects.filter(class_date=day_x)
all_matches = day_x_classes
paginator = Paginator(all_matches, 10)
page = request.GET.get('page')
try:
matches = paginator.page(page)
except PageNotAnInteger:
matches = paginator.page(1)
except EmptyPage:
matches = paginator.page(paginator.num_pages)
return render_to_response('preview.html', {'today': today, 'tomorrow': tomorrow,
'past_classes': past_classes, 'day_x': day_x, 'day': day,
'day_x_classes': day_x_classes, 'yesterday': yesterday, 'matches': matches,
'page': page}, context_instance = RequestContext(request))
#urls.py
(r'^upcoming_class_list/plus/(\d{1,2})/$', upcoming_class_list),
#preview.html
<h3>Classes for {{ day_x }}</h3>
{% if matches %}
<div class="pagination">
<span class="step-links">
{% if matches.has_previous %}
<a href="?page={{ matches.previous_page_number }}">« previous </a>
{% endif %}
<span class="current">
Page {{ matches.number }} of {{ matches.paginator.num_pages }}
</span>
{% if matches.has_next %}
<a href="?page={{ matches.next_page_number }}"> next »</a>
{% endif %}
</span>
</div>
{% if day_x_classes %}
<ul type=none>
{% for class in day_x_classes %}
<li>
<ul type=none>
<li><strong>{{ class.type }}</strong></li>
<li>Teacher: <a href="/profiles/{{ class.teacher }}">{{ class.teacher }}</a></li>
<li>Class Description: {{ class.description }}</li>
...
</ul>
</li><br />
{% endfor %}
</ul>
{% endif %}
{% else %}
<p>There are currently no scheduled upcoming classes for {{ day_x }}.</p>
{% endif %}