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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:13:37+00:00 2026-05-28T08:13:37+00:00

I am trying to do a basic search feature but I am having a

  • 0

I am trying to do a basic search feature but I am having a small issue. When I go to the template that has the search form, it is displaying all the items before I even try to search. Is there a way to show a blank template until the user has put in a search term and hit the search button?

Example:

[Search field][Button]

1
2
3
etc

views.py

def view_player_home(request):
    if request.method == 'GET':
        form = searchPlayerForm(request.GET)
        if form.is_valid():
            string = form.cleaned_data.get('text')
            players = Player.objects.filter(Q(first_name__icontains = string)|Q(last_name__icontains = string))
            return render_to_response('player/player.html', {'form': form, 'players':players}, context_instance=RequestContext(request))
else:
    form = searchPlayerForm()
return render_to_response('player/player.html', {'form': form}, context_instance=RequestContext(request))

forms.py

class searchPlayerForm(forms.Form):
    text = forms.CharField(label = "Search")

    def __init__(self, *args, **kwargs):
        super(searchPlayerForm, self).__init__(*args, **kwargs)
        self.fields['text'].required = False

template

{% extends "base.html" %}

{% block content %}

<h5>Find Player</h5>
<form method="GET" action="">
    {% csrf_token %}
    {{ form.as_table }}
    <input type="submit" value="Submit"/>
</form>

{% if players %}
   {% for p in players %}
       {{ p.first_name }} {{ p.last_name }}
   {% endfor %}
{% else %}
   No Players
{% endif %}

{% endblock %}
  • 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-28T08:13:37+00:00Added an answer on May 28, 2026 at 8:13 am

    One change should do it:

    if request.method == 'GET':
    

    should be

    if request.GET:
    

    The underlying issue is that your request method is always GET, so you never go into the else block or to the bottom of the function.

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

Sidebar

Related Questions

I am trying to code the relevency features of a basic search engine that
I'm trying to create a basic submit form (like the dajaxice's example) but i
I am trying to implement a search page with 2 tabs: Basic Search Options
I'm trying to handle proximity search for a basic store locater in Django. Rather
I am trying to implement a basic full-text search with MySQL. I wrote this
Trying to search for a more elegant/overall solution to our common/basic data export tasks
The basic problem is that upon trying to uninstall the default SQL 2005 express
I am trying to build a very basic fulltext search app in php. I
I'm trying to implement search functionality in my app, which is very basic at
I am trying to build a basic templating engine. Like the template engines already

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.