Hi,

I am paginating the output of a query. Everything works fine and the
first page of results is displayed. The problem is that the url to
access pages 2 (http://127.0.0.1:8000/search/?page=2) and following
fall back to the search form and do not display the second page of
results.

urls.py
urlpatterns = patterns('',
....
    (r'^search/', views.search_photos),
)

views.py
def search_photos(request):
    if request.method == 'POST':
        form = SearchForm(request.POST)
        if form.is_valid():
            querytext = form.cleaned_data['querytext']
            search_result =
Photo.objects.filter(title__icontains=querytext).order_by('date_taken')
            paginated_list = Paginator(search_result, 25)
            try:
               page = int(request.GET.get('page', '1'))
            except ValueError:
               page = 1
            try:
               paginated_list = paginated_list.page(page)
            except (EmptyPage, InvalidPage):
               paginated_list =
paginated_list.page(paginated_list.num_pages)
            return render_to_response('photologue/
photo_list_searched.html', {'paginated_list': paginated_list})
    else:
        form = SearchForm()
    return render_to_response('search.html', {'form': form,})

search.html
...
{% block content %}
      <form id="SearchForm" action="/search/" method="post">
        <table>
            {{ form.as_p }}
        </table>
        <input type="submit" value="Submit">
       </form>


photo_list_searched.html
...
{% block title %}
{% if paginated_list.paginator.count %}
<p>Found {{ paginated_list.paginator.count }} photos, displaying 25
per page. </p>
{% else %}
<p>No photos were found.</p>
{% endif %}
{% endblock %}

{% block content %}
{% if paginated_list.paginator.count %}
<div class="pagination">
    <span class="step-links">
        {% if paginated_list.has_previous %}
            <a href="?
page={{ paginated_list.previous_page_number }}">previous</a>
        {% endif %}
        <span class="current">
            Pages {{ paginated_list.number }} of
{{ paginated_list.paginator.num_pages }}
        </span>
        {% if paginated_list.has_next %}
            <a href="?
page={{ paginated_list.next_page_number }}">next</a>
        {% endif %}
        </span>
</div>
<div class="gallery-photo">
    <table>
    {% for photo in paginated_list.object_list %}
         <tr>
         <td><a href="{{ photo.get_absolute_url }}"><img
src="{{ photo.get_thumbnail_url }}" alt="{{ photo.title }}" border="0"/
></a></td>
         <td><h2>{{photo.title}}</h2>
             <p>Date Taken: {{photo.date_taken|date:"j F Y"}}</p>
             <p>Link to large image: <a
href="{{ photo.image.url }}">{{ photo.image.url }}</a></p></td>
         </tr>
     {% endfor %}
    </table>
 </div>
{% else %}
<p>Please try again using more specific words. If you are still unable
to find what you are looking for, use the contact page to request
help.</p>
{% endif %}
{% endblock %}

Thanks in advance,

Andrew

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to