Friday, March 1, 2019

how to do math operations inside Django template?

1. Install "django-mathfilters" package using pip
   pip install django-mathfilters

2. Open settings.py file of your Django project and add  'mathfilters' in INSTALLED_APPS section.
   After this your settings.py file's INSTALLED_APPS section will look as follows
   INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'mathfilters',
   ]

3. Now you can do the basic math operations like add, sub, mul, div etc., like as follows
    add - {{ 8|add:4 }}
    mul - {{ your_var|mul:2 }}

For more details please refer -> https://pypi.org/project/django-mathfilters/

2 comments:

Jason Adams said...

This is amazing, thank you. Also, check this out if you are looking for professional website or logo design services:


Buy Logo

Anonymous said...

First I want to tell you Thank you for sharing it with us.
I am really Happy and impressed to see this blog!
law essay writing help