O'Reilly logo

Django Project Blueprints by Asad Jibran Ahmed

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding search

If you look at our home page right now, it should be a list of 50 random products from our database. You can open it at http://127.0.0.1:8000 and it should look similar to this:

Adding search

What we'd like to do is add a basic search form to this page. The form will just be one field that accepts a search term and button to perform the search. The search term will perform a search on the name field of our products list.

Let's create a simple Django form and add it to our page. Create a new main/forms.py file and add the following code:

from django import forms


class SearchForm(forms.Form):
    name = forms.CharField(required=False)

Next, we need to display ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required