Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

When PAGINATION_DISABLE_LINK_FOR_FIRST_PAGE is True, the page 1 url links to the current page. #6

Closed
christianmlong opened this issue Mar 7, 2017 · 6 comments · Fixed by #9

Comments

@christianmlong
Copy link

christianmlong commented Mar 7, 2017

When PAGINATION_DISABLE_LINK_FOR_FIRST_PAGE is True, the href for the anchor tag for the number 1 page is blank. What this means is, when you click on the number 1, you just stay on the current page instead of going to page 1.

Look at this snippet of generated html. We are on page 4. If you hover over the number 1, the tooltip will show /current/path/?page=4. And, if you click on the number 1, nothing happens. You stay on the current page.

<div class="pagination">
  <a href="?page=3" class="prev">‹‹ previous</a>
  <a href="" class="page">1</a>
  <a href="?page=2" class="page">2</a>
  <a href="?page=3" class="page">3</a>
  <span class="current page">4</span>
  <a href="?page=5" class="page">5</a>
  <a href="?page=6" class="page">6</a>
  ...
  <a href="?page=8585" class="page">8585</a>
  <a href="?page=8586" class="page">8586</a>
  <a href="?page=5" class="next">next ››</a>
</div>

The problem is, the href for page 1 is blank. I think the bug is here, on line 25 of pagination.html.

{% if disable_link_for_first_page and page == 1 %}
<a href="{{ request.path }}{% if getvars %}?{{ getvars|slice:"1:" }}{% endif %}" class="page">{{ page }}</a>

I think there is another instance of the same problem on line 7 of pagination.html. When you are on page 2, the href for the anchor for the word "previous" is also blank. So if you are on page 2, and you click "previous", you stay on page 2.

@christianmlong
Copy link
Author

Django 1.10.6, dj-pagination 2.2.1

My template configuration

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
       'DIRS': [
            SITE_TEMPLATES_DIR,
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

@pydanny
Copy link
Owner

pydanny commented Mar 8, 2017

If you submit a pull request I'll create a new PyPI release. 😄

@chengxiao
Copy link

Same problem with @christianmlong
how to fix it?

@christianmlong
Copy link
Author

I ended up just using PAGINATION_DISABLE_LINK_FOR_FIRST_PAGE=False. The urls aren't as clean, but it works.

@strogonoff
Copy link

I believe the problem is that {{ request.path }} is empty on lines 7 and 25 because {{ request }} does not get passed to the pagination template. Pull request pending. I’m using my fork in the meantime and not experiencing this issue anymore.

@pydanny pydanny closed this as completed in #9 Aug 1, 2017
@pydanny
Copy link
Owner

pydanny commented Aug 1, 2017

Pushed version 2.3 to PyPI: https://pypi.python.org/pypi/dj-pagination

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants