Created
May 10, 2013 20:23
-
-
Save omeinusch/5557123 to your computer and use it in GitHub Desktop.
Currency-filter for Django's template engine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django import template | |
from django.conf import settings | |
from django.template.defaultfilters import floatformat | |
register = template.Library() | |
""" | |
This little code assumes, that you have a setting named CURRENCY with a value like 'EUR' or 'USD' or u'€' | |
""" | |
@register.filter | |
def currency(value): | |
if value is None: | |
value = 0 | |
return '%s %s' % (floatformat(value, 2), settings.CURRENCY) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment