django-mathfilters is a Python 3 module that provides different simple math filters for Django.
Django provides an add template filter, but no corresponding subtracting, multiplying or dividing filters.
Django ticket #361 has been closed as wontfix, so I had to create an alternative that is easy to install in a new Django project.
It currently supports int, float and Decimal types, or any other type that can be converted to int or float.
Installation
$ pip install django-mathfilters
Then add mathfilters to your INSTALLED_APPS.
Usage
You need to load mathfilters at the top of your template. The script provides the following filters:
sub – subtraction
mul – multiplication
div – division
intdiv – integer (floor) division
abs – absolute value
mod – modulo
addition – replacement for the add filter with support for float / decimal types
Example:
{% load mathfilters %}
...
<h1>Basic math filters</h1>
<ul>
<li>8 + 3 = {{ 8|add:3 }}</li>
<li>13 - 17 = {{ 13|sub:17 }}</li>
{% with answer=42 %}
<li>42 * 0.5 = {{ answer|mul:0.5 }}</li>
{% endwith %}
{% with numerator=12 denominator=3 %}
<li>12 / 3 = {{ numerator|div:denominator }}</li>
{% endwith %}
<li>|-13| = {{ -13|abs }}</li>
</ul>
Version Support
This module officially supports Python 3.5+ as well as PyPy3. Support for Python 3.3 and 3.4 is provided on best-effort basis, but there are no CI tests for it.
Supported Django versions are 1.11+, 2.x and 3.x.
License
MIT License, see LICENSE file.
Metadata
Release files for django-mathfilters 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-mathfilters-1.0.0.tar.gz | 5.7 kB | Without provenance | Details for django-mathfilters-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_mathfilters-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for django_mathfilters-1.0.0-py3-none-any.whl |
Total release size: 11.6 kB
Release files / django-mathfilters-1.0.0.tar.gz
| Download URL | django-mathfilters-1.0.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9b892ef6dfc893683e75cfd0279c187a601ca68f4684c38f9da44657fb64b07
|
|
BLAKE2b-256 checksum How to use checksums |
caa61e8262e52aa3cbfae277bc97c23dd4f1f6c7d7c3adaf45fb41132c312a40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.8.1
|
Release files / django_mathfilters-1.0.0-py3-none-any.whl
| Download URL | django_mathfilters-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64200a21bb249fbf27be601d4bbb788779e09c6e063170c097cd82c4d18ebb83
|
|
BLAKE2b-256 checksum How to use checksums |
8ac6107083a63a564664830e352af330563763654972d27d56e42d9b6e3c744f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.8.1
|
Security for django-mathfilters 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.