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 7843421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:32:43+00:00 2026-06-02T16:32:43+00:00

I’m developing an app using Django and I made a simple search inside a

  • 0

I’m developing an app using Django and I made a simple search inside a very big database and a Paginator for the results. The problem is that when I try to go to the second results page, I lose the searched term from my link.

I’ve tried to rewrite the search word in the input field with JQuery, that didn’t work. I tried to re-send the value from the server-side to the input field, didn’t work either.

How can I manage to keep it for the second page of results? Any other hints?

This is my code, the relevant part at least:

results.html:

...
<form method="POST" id="searchForm"  action="{% url ps.views.search page=1 searchTerm='__search_term__' %}">
    {% csrf_token %}
    <input type="text" id="billSearched">
    <input type="submit" value="{% trans "Look for" %}">
</form>
 ...
<div class="pagination">
    {% if current_page.has_previous %}
        <a href="{% url ps.views.search page=current_page.previous_page_number searchTerm='__search_term__' %}">previous</a>
    {% endif %}

    <span class="current">
        Page {{ current_page.number }} of {{ current_page.paginator.num_pages }}
    </span>

    {% if current_page.has_next %}
        <a href="{% url ps.views.search page=current_page.next_page_number searchTerm='__search_term__' %}">next</a>
    {% endif %}
</div>

search.py:

def search(request,page,searchTerm):
    found_bills = Bill.objects.filter(name__icontains=searchTerm)
    searchedWord = str(searchTerm)
    paginator = Paginator(found_bills,25)
    try:
        current_page = paginator.page(page)
    except (EmptyPage, InvalidPage):
        current_page = paginator.page(paginator.num_pages)
    bills_list = list(current_page.object_list)
    return render_to_response('results.html',{"bills_list":bills_list,"current_page":current_page,"searchTerm":searchTerm,"searchedWord":searchedWord},context_instance=RequestContext(request))

And also the urls.py althought I’m not sure it’s helpful 🙂

urlpatterns = patterns('',
    url(r'^$','ps.views.bills',name="bills"),
    url(r'^i18n/', include('django.conf.urls.i18n')),
    url(r'^search/(?P<page>\d+)/(?P<searchTerm>\w*)','ps.views.search',name="search"),)

I should mention that in the address bar the searched term when I go to page 2 is "__search_term__".

i.e. http://127.0.0.1:8000/search/2/__search_term__

Thank you in advance! 🙂

  • 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-06-02T16:32:43+00:00Added an answer on June 2, 2026 at 4:32 pm

    Change your form method to GET instead of POST, then build your links with the search term as part of the URL’s query-string like this…

    <a href="?page={{ contacts.previous_page_number }}">previous</a>
    

    https://docs.djangoproject.com/en/dev/topics/pagination/

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a

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.