Django Filter

Adi Ramadhan
2 min readJun 20, 2022


A library like django form to filter queryset.


Official docs django-filter.

Project file structure.
templates folder, base.html, books.html, myapp/filters, myapp/ files are manually created (new files), other files are auto-generated.

final file project structure

Step 1: Preparation, Create Django Project, Inital Migration
create virtualenv: virtualenv venv
start virtualenv: venv/Scripts/activate
install Django in virtualenv: pip install django==3.2 django-filter
Create Django: django-admin startproject myproject
Go to myproject folder: cd myproject
Initial Migration: python migrate

Step 2: Create Django Apps and Register django-filter
Create apps: python startapp myapp
Add myapp to INSTALLED_APPS in myproject/

INSTALELD_APPS in myproject/

Step 3: Add Models and Register in Models in admin

Update myapp/


Update myapp/


Step 4: Makemigrations and Migrate
Make migrations: python makemigrations
Migrate: python migrate

Step 5: Create Superuser
Create superuser: python createsuperuser
Type username, email password and retype password

Step 6: Create in myapp


Step 7: Set up Templates Folder
Create folder templates in myapp

Add template directory in TEMPLATES parameter in myproject/

Path(BASE_DIR, 'myapp', 'templates')
TEMPLATES in myproject/

Step 8: Create HTML template
Create bootstrap base.html


Create books.html


Step 9: Create views function in


Step 10: Set up URLs

Create myapp/


Update myproject/


Step 11: Run Server and Testing
Run Server: python runserver
Open admin site:
Add some books

admin site

Open book site and filter test:

book list wit filter