django-mathfilters
django-mathfilters is a pip-installable 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.
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
abs – absolute value
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>
License
MIT License, see LICENSE file.
Metadata
Release files for django-mathfilters 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-mathfilters-0.1.1.tar.gz | 3.2 kB | Details |
Release files / django-mathfilters-0.1.1.tar.gz
| Download URL | django-mathfilters-0.1.1.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ebdfea1b45d5ab8853f7165477d9ee2c0731d87f67a1a210d509535fc1fb19c
|
|
BLAKE2b-256 checksum How to use checksums |
48919d7c9572fba28fcb8ab797d62e4149a9501482a40b056815188e5f84870e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |