My Paginator not working at the last page button

when click next and previous button is working, but the last page not working

model.py

class VenueForm(ModelForm):
    class Meta:
        model = Venue
        fields = (
            'name', 'address', 'zip_code', 'phone', 'web', 'email_address'
        )
        labels = {
            'name': '',
            'address': '',
            'zip_code': '',
            'phone': '',
            'web': '',
            'email_address': '',
        }
        widgets = {
            'name': forms.TextInput(attrs={
                'class': 'form-control', 'placeholder': 'Venue Name'}),
            'address': forms.TextInput(attrs={
                'class': 'form-control', 'placeholder': 'Address'}),
            'zip_code': forms.TextInput(attrs={
                'class': 'form-control', 'placeholder': 'Zip Code'}),
            'phone': forms.TextInput(attrs={
                'class': 'form-control', 'placeholder': 'Phone'}),
            'web': forms.TextInput(attrs={
                'class': 'form-control', 'placeholder': 'Web'}),
            'email_address': forms.EmailInput(
                attrs={'class': 'form-control', 'placeholder': 'Email'}),
        }

view.py

from .models import Event, Venue
from django.core.paginator import Paginator

def list_venues(request):
    venue_list = Venue.objects.all()
    p = Paginator(Venue.objects.all(), 3)
    page = request.GET.get('page')
    venues = p.get_page(page)
    nums = "a" * venues.paginator.num_pages
    return render(request, 'events/venue.html', {
        'venue_list': venue_list, 'venues': venues, 'nums': nums})

events/venue.html

<nav aria-label="Page navigation example">
  <ul class="pagination justify-content-center">
    {% if venues.has_previous %}
    <li class="page-item">
      <a class="page-link" href="?page=1">&laquo; First</a>
    </li>
    <li class="page-item">
      <a class="page-link" href="?page={{ venues.previous_page_number }}">Previous</a>
    </li>
    {% endif %}
    {% for i in nums %}
    <li class="page-item">
      <a class="page-link" href="?page={{ forloop.counter }}">{{ forloop.counter }} </a>
    </li>
    {% endfor %}
    {% if venues.has_next %}
    <li class="page-item">
      <a class="page-link" href="?page={{ venues.next_page_number }}">Next</a>
    </li>
    <li class="page-item">
      <a class="page-link" href="?page={{ venues.paginator.num_pages ))">Last &raquo;</a>
    </li>
    {% endif %}
  </ul>
</nav>

i don't know why, every create a question it show me red ! to me (It looks like your post is mostly code; please add some more details) and i always use long time to pass it

Back to Top