I would like to have a "pagination" where I would have one image per page. My current code is pasted below. Unfortunatley now I get ALL images on EVERY pagination. Which is already a step in the right direction but not quite what I want.
How can I just have one image per page e.g Images 1 of my os.listdir and below that a link to the next Image in that os.listdir?
views.py
def p_main_page(request):
stimuli_list=os.listdir('/Users/Me/Images')
p = Paginator(stimuli_list, 1)
urllist = ['/site_media/Images/%s' % url for url in stimuli_list]
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
stimuli = p.page(page)
except (EmptyPage, InvalidPage):
stimuli = p.page(p.num_pages)
return render_to_response('stimulilist.html', {"stimuli": stimuli,
"urllist": urllist})
template:
<html>
<head>
<title> Stimuli </title>
</head>
<body>
<p>
{% for url in urllist %}
<img src='{{ url }}' />
{% endfor %}
</p>
<div class="pagination">
<span class="step-links">
{% if stimuli.has_previous %}
<a href="?page={{ stimuli.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ stimuli.number }} of {{ stimuli.paginator.num_pages }}.
</span>
{% if stimuli.has_next %}
<a href="?page={{ stimuli.next_page_number }}">next</a>
{% endif %}
</span>
</div>
<body>
</html>