Skip to content
Related Articles
Get the best out of our app
Open App

Related Articles

Custom Template Filters in Django

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Django is a Python-based web framework that allows you to quickly create efficient web applications. It is also called batteries included framework because Django provides built-in features for everything including Django Admin Interface, default database – SQLlite3, etc. 

What is filters in Django template language (DTL) ?

Before move to see the how to make custom filters in Django Template Language, let’s  learn what is filters in Django.

  • Filter is also the important feature of our template language.
  • Filters are basically used to modify or filter your variables.
  • You have to use this pipe ( | ) symbol to apply filter in any variables.

For example :-

So this filter will modify this variable value in lowercase

{{ variable_name |  filter_name }}

How to create custom Template Filter in Django?

First of install create the django project using following command :-

django-admin startproject myproj
cd myproj

Then create the new app  inside myproj

For Ubuntu

python3 startapp main

Add app name in inside INSTALLED_APPS

Add this view in your


from django.shortcuts import render
# Create your views here.
def home(request):
    return render(request,"home.html",{"value":value})

Now lets make the templatetags directory inside our main folder

and don’t forget to create file inside templatetag directory

and then create file


from django import template
register = template.Library()
def low(value):
    return value.lower()

Create a directory in main directory add name it as templates

Inside the templates directory create a file and name it as home.html


<!DOCTYPE html>
    <title>Welcome To GFG</title>
    {% load lower_filter %}

Create a file in main directory and name it as


from django.urls import path
from .views import *
urlpatterns = [
    path('', home,name="home"),



from django.contrib import admin
from django.urls import path,include
urlpatterns = [

open cmd or terminal

For Ubuntu

python3 runserver

Output :-

My Personal Notes arrow_drop_up
Last Updated : 01 Feb, 2021
Like Article
Save Article
Similar Reads
Related Tutorials