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

  • Home
  • SEARCH
  • 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 7910103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:43:57+00:00 2026-06-03T12:43:57+00:00

I’m trying to make a simple search and return results in a paginated form.

  • 0

I’m trying to make a simple search and return results in a paginated form. Whenever I try to go to the second page, my search term is lost and thus my second page has no results.

I’ve found and followed the Pagination example in the Djangoproject tutorial, but I haven’t found an example on how to write my URL for the search view.

I’ve used POST method in my form previously, for when I had little data to display (although now, after a bit of research, I know the usage difference between GET and POST). When I gained lots more data, I was constrained to use Pagination. Thus, I’ve changed my form method to GET but here is my problem, I don’t know how to describe my URL so the data is sent to the right view.

I’ve tried to make it work with POST but with no success. Finally I decided to stick to GET example but stumbled on this URL thing that’s keeping me back.

Here is the code in the template and the URLs file:

search.py:

<form method="GET" id="searchForm" action="/search/?page=1">
    {% csrf_token %}
    <input type="text" id="billSearched" name="q_word">
    <input type="submit" value="{% trans "Look for" %}">
</form>

urls.py:

urlpatterns = patterns('',
    url(r'^$','ps.views.bills',name="bills"),
    url(r'^i18n/', include('django.conf.urls.i18n')),
    url(r'^search/$','ps.views.search',name="search"),)

I’ve tried many forms for the URL but none have succeeded.

i.e.:

url(r'^search/(?P<page>\d+)/$','ps.views.search',name="search")
url(r'^search/','ps.views.search',name="search")
url(r'^search/(?P<page>\d+)/(?P<searchTerm>\w*)','ps.views.search',name="search")

Any explanation / solution would be really appreciated. Thank you in advance!

UPDATE:

def search(request):
    searchTerm = ""
    page = 1
    import pdb
    pdb.set_trace()
    if 'q_word' in request:
        searchTerm = request.GET['q_word']
    if 'page' in request:
        page = request.GET['page']
    found_bills = Bill.objects.filter(name__icontains = searchTerm)
    paginator = Paginator(found_bills,25)
    try:
        current_page = paginator.page(page)
    except PageNotAnInteger:
        current_page = paginator.page(1)
    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,},context_instance=RequestContext(request))

UPDATE #2:

If I use pdb I can see that there is no data being passed from the client to the server. Got to work on that, but still, any information and/or hints would be really appreciated as they can shorten my search time 🙂

(Pdb) request.GET

<QueryDict: {u'page': [u'1']}>

  • 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-03T12:43:59+00:00Added an answer on June 3, 2026 at 12:43 pm

    If your form’s method is GET, you cannot append a query string to the action, because the browser will overwrite it. You can only do that if your form method is POST.

    Change your form to this:

    <form method="GET" id="searchForm" action="/search/">
        <input type="text" id="billSearched" name="q_word">
        <input type="submit" value="{% trans "Look for" %}">
    </form>
    

    In your view:

    from django.shortcuts import render
    
    def search(request):
        if 'q_word' in request:
            searchTerm = request.GET['q_word']
    
        found_bills = Bill.objects.filter(name__icontains = searchTerm)
        page = request.GET.get('page')
        paginator = Paginator(found_bills,25)
        try:
            current_page = paginator.page(page)
        except PageNotAnInteger:
            current_page = paginator.page(1)
        except (EmptyPage, InvalidPage):
            current_page = paginator.page(paginator.num_pages)
        # bills_list = list(current_page.object_list) - not needed
        return render(request,
                      'results.html',{"results":current_page,"term": searchTerm})
    

    In results.html:

    {% for bill in results %}
         # .. display bill stuff
    {% endfor %}
    
    {% if results.has_previous %}
         <a href="{% url search %}?page={{ results.previous_page_number }}&q_word={{ term }}">previous</a>
    {% endif %}
    
    {% if results.has_next %}
          <a href="{% url search %}?page={{ result.next_page_number }}&q_word={{ term }}">next</a>
    {% endif %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
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 trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns 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.