O
O
Ozrae2020-05-08 15:56:13
Django
Ozrae, 2020-05-08 15:56:13

How to create a button click condition?

There is a paginator like this:

<ul class ='paginate'>
            <li>
                <a href="#">Previous</a>
            </li>
            
            {% for n in page_obj.paginator.page_range %}
            {% if n > page_obj.number|add:-3 and n < page_obj.number|add:3 %}
            <li><a href="?page={{ n }}">{{ n }}</a></li>
            {% endif %}
            {% endfor %}
            <li><a href="#">Next</a></li>
        </ul>


You need to implement the Previous and Next buttons. I see two ways to do this: create a condition if the button is pressed - add or subtract to the variable n and follow the link. Or write something like n+1 or n-1 already in the link. I do not understand how to implement all this, it gives an error on my attempts. Please tell me both ways.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-05-08
@bacon

(Wearily) read the docs https://docs.djangoproject.com/en/3.0/ref/paginato... and don't come up with some crazy stuff.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question