Skip to main content

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)

Source distribution for django-mathfilters 0.1.1
File Size Uploaded Provenance Actions
django-mathfilters-0.1.1.tar.gz 3.2 kB Without provenance Details for django-mathfilters-0.1.1.tar.gz

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

Security for django-mathfilters 0.1.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page