Django maths using widthratio27 Jun 2015
I use a lot of Django templating and one of my pet peeves is it’s inability to handle simple maths. Seriously, why?
Sure, you can build your own functions for this, but in my opinion, maths is something that should be built-in. Yeah, you can
add, but that’s about it.
Now, if you’re only using integers, you can be quite creative with
widthratio to solve many math expressions:
- The code above has an extra space between
}to avoid my Jekyll trying to parse it…
widthratiorounds everything to integers. So, if you need precise results you should really look elsewhere.
Have a question about this post, a project or anything else?
Let's have a conversation on Twitter.