Search code examples
djangopython-2.7virtualenvdjango-custom-tags

How do I resolve the "'mathfilter' tag 'addition' stopped working since replicating django project" error?


Recently I moved a Django Project to a new virtual environment. Everything appears to be working fine, with the exception of the following error:

TemplateSyntaxError at /profile/

Invalid filter: 'addition'

Request Method:     GET
Request URL:    http://example.com/example/
Django Version:     1.9.12
Exception Type:     TemplateSyntaxError
Exception Value:    

Invalid filter: 'addition'

Exception Location:     /opt/example/local/lib/python2.7/site-packages/django/template/base.py in parse, line 516
Python Executable:  /usr/local/bin/uwsgi
Python Version:     2.7.3

I narrowed this down to this line of code:

 {% with deeb_percent=stat.deeb_base|addition:stat.deeb_deal %}

Further investigation and I found this: https://github.com/dbrgn/django-mathfilters , it appears 'addition' is a custom filter which is part of mathfilters. The documentation I linked says to run:

pip install django-mathfilters

I have checked with pip freeze, and mathfilters is installed.

appdirs==1.4.3
backports.ssl-match-hostname==3.5.0.1
beautifulsoup4==4.5.3
Django==1.9.12
django-appconf==1.0.1
django-autocomplete-light==3.2.1
django-compat==1.0.8
django-compressor==1.6
django-dual-authentication==1.0.0
django-hijack==2.0.1
django-htmlmin==0.8.0
django-ipware==1.1.2
django-mathfilters==0.3.0
django-modelcluster==3.0.1
django-taggit==0.22.0
django-treebeard==4.1.0
django-widget-tweaks==1.4.1
djangorestframework==3.6.2
html5lib==0.9999999
packaging==16.8
Pillow==3.0.0
pyparsing==2.2.0
pytz==2015.7
requests==2.13.0
simplejson==3.10.0
six==1.10.0
slackclient==1.0.5
Unidecode==0.4.20
wagtail==1.9
websocket-client==0.40.0
Willow==0.4

Then add mathfilters to your INSTALLED_APPS.

I have also checked INSTALLED_APPS in the project settings.py and mathfilters is also loaded:

INSTALLED_APPS = [
...
'mathfilters',
...

]

At the top of the template in question 'mathfilters' is loaded:

{% extends "base.html" %}
{% load i18n %}
{% load static %}
{% load extra %}
{% load mathfilters %}

If i change 'addition' in the template to 'add' the template works ok.

{% with deeb_percent=stat.deeb_base|addition:stat.deeb_deal %}

But I don't want to do this for every single template in multiple places, and also am uncomfortable leaving this 'broken' since I installed the project in a new virtualenv.

Why aren't the mathfilters working? and how can I resolve this error?


Solution

  • https://github.com/dbrgn/django-mathfilters

    addition – replacement for the add filter with support for float / decimal types

    Update to mathfilter to 0.4.0, things will be back to normal