Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6891947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:28:25+00:00 2026-05-27T06:28:25+00:00

I am using a Django Paginator and I want to have multiple available get

  • 0

I am using a Django Paginator and I want to have multiple available get parameters, such as:
page=1
sort_by=price

However, in my template tags I have:

Showing items sorted by {{ SORT_PARAM }}.
Showing {{ ITEMS_PER_PAGE }} items per page.

{% if has_prev %}
<a href="?page={{ prev_page }}">Previous</a> |
{% endif %}

However, this does not preserve the other GET variables. What I mean is, if I’m viewing

page/?page=1&sort_by=price

and I click the link in the template fragment above, I will go to

page=2

instead of

page=2&sort_by=price

What I mean is, the a href does not preserve the other GET parameters.

One solution is I could type all the possible GET parameters in the a href, such as

<a href="?page={{ prev_page }}&items_per_page={{ ITEMS_PER_PAGE }}&sort_param={{ SORT_PARAM }}">Previous</a>

but this will become less scalable the more arguments I want to add to my browsing. I’m guessing there should be an automated way to obtain all GET parameters, and then pass those and one more?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:28:25+00:00Added an answer on May 27, 2026 at 6:28 am

    You can create a ‘parameter-string’. Let’s supose that in your code you have:

    my_view( request, page, options):
        sort_choices = {P:'price',N:'name', ...}
        n_item_choices = {'S':5, 'L':50, 'XL':100)
        ascending_descending_choices = {'A':'', 'D':'-'}
        ...
    

    then you can concatenat options as:

    options='P-S-D'  #order by price, 5 items per page, descending order
    

    encode opions as:

    <a href="?page={{ prev_page }}&options={{ options }}">Previous</a>
    

    then, in urls.py capture options and in view:

    my_view( request, page, options):
       ... #choides ....
       try:
          optionsArray = options.split('-')
          sort_by = sort_choices[ optionsArray[0]  ]
          n_ites_page = n_item_choices[ optionsArray[1]  ]
          asc_or_desc = ascending_descending_choices[ optionsArray[2]  ]
          ...
       except:
          somebody is playing ....
    

    with this method you are free to add more paginations options without modify urls.py, all you need is to append options at the end of string options . This has advantages but also some dangers: I hope you can identify risks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Django Paginator everywhere on my website and even wrote a special template
I'm using Django and Python 2.6, and I want to grow my application using
I'm using django and when users go to www.website.com/ I want to point them
While using django.core.paginator import ObjectPaginator, I'm getting this error: NeedIndexError: The built-in indices are
Im using Django 1.2.3. I have login functionality in my site using django.contrib.auth.views.login .
I´m using django-photologue (with 1pinax) and want to scale images to a box (100px
I have created an Employee management system using Django. I have done a filtering
Using django, I am authenticating the user through Google. I get the initial request
Using django-contact-form , I have overridden the form class: from contact_form.forms import ContactForm from
Am using django forms on my app. I have a model Client like this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.