Mathematical template filters for Django
Project description
django-numfilters is a collection of template filters for Django who provides access to several basic mathematical functions.
Download
To install it by using pip:
$ pip install django-numfilters
or by using easy_install:
$ easy_install django-numfilters
You can also pot for installing it from source:
$ git clone git@github.com:amatellanes/django-numfilters.git $ cd django-numfilters $ python setup.py install
Installation
To enable django-numfilters in your Django project, you need to add django_numfilters to INSTALLED_APPS:
INSTALLED_APPS = ( ... 'django_numfilters', ... )
Usage
This section provides a summary of django-numfilters features.
Firstly, you need make filters available to your templates using {% load numfilters %} tag. After this, you can use next tags:
- abs
Returns the absolute value of a, for a number.
- add
This filter is provided by Django.
- sub
Returns a - b, for a and b numbers.
- mul
Returns a * b, for a and b numbers.
- div
Returns a / b, for a and b numbers (classic division).
- mod
Returns a % b, for a and b numbers.
- floordiv
Returns a // b, for a and b numbers.
- pow
Returns a ** b, for a and b numbers.
- sqrt
Return the square root of a, for a number.
Example
{% load numfilters %}
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example django-numfilters</title>
</head>
<body>
<ul>
<li>abs(-41) = {{ -41|abs }}</li>
<li>23 - 7 = {{ 23|sub:7 }}</li>
<li>25 * 2 = {{ 25|mul:2 }}</li>
<li>32 / 4 = {{ 32|div:4 }}</li>
{% with a=15 b=3 %}
<li>15 % 3 = {{ a|mod:b }}</li>
{% endwith %}
{% with a=5 b=2 %}
<li>5 // 2 = {{ a|floordiv:b }}</li>
{% endwith %}
<li>pow(5, 2) = {{ 5|pow:2 }}</li>
{% with a=64 %}
<li>sqrt(64) = {{ a|sqrt }}</li>
{% endwith %}
</ul>
</body>
</html>
Testing
You can see the current Travis CI build here: https://travis-ci.org/amatellanes/django-numfilters.
Changelog
Release 0.1.1 (no codename, released on December 26th 2014)
Fix minor bugs.
Release 0.1.0 (no codename, released on July 20th 2014)
Initial release.
License
MIT License, see LICENSE file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-numfilters-0.1.1.tar.gz
.
File metadata
- Download URL: django-numfilters-0.1.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe5971bd6238cf45ccc5e1f1f2b859da6c75ae4c3b6ab46112baaf424defa24b |
|
MD5 | b615e16bfe3a4151914ba90a050ba1a0 |
|
BLAKE2b-256 | bbcf3c20971da0a20d4fa8e81096d44d7dc135f7605cddfd9072b20272946dbf |