title: How to implement search function in django?
body: <p>I have many books in a database. Searching the database returns nothing(empty queryset).</p>
  
  <p>In the menu:</p>
  
  <pre><code>&lt;form name="myform" method="POST" action="{% url 'search' %}"&gt;  
      {% csrf_token %}
      &lt;input type="text" name="search" placeholder="Search" /&gt;
  &lt;/form&gt; 
  </code></pre>
  
  <p>views.py,</p>
  
  <pre><code>def search(request):        
      if request.method == 'POST':      
          book_name =  request.POST.getlist('search')      
          try:
              status = Add_prod.objects.filter(bookname__icontains=book_name)
              #Add_prod class contains a column called 'bookname'
          except Add_prod.DoesNotExist:
              status = None
          return render(request,"search.html",{"books":status})
      else:
          return render(request,"search.html",{})
  </code></pre>
  
  <p>My template file,</p>
  
  <pre><code>{% if books %}
      &lt;a href="{% url 'buy_book' pk=books.pk %}"&gt;
      &lt;!--Upon successful search book image with hyperlink appears --&gt;
      &lt;img src="{{books.image.url}}" alt="No Image"&gt;&lt;/a&gt;
      &lt;p&gt;{{books.bookname}}&lt;/p&gt;
      &lt;p&gt;Rs.{{books.price}}&lt;/p&gt;   
  {% endif %}
  </code></pre>