Skip to content

Instantly share code, notes, and snippets.

@omeinusch
Created May 10, 2013 20:23
Show Gist options
  • Save omeinusch/5557123 to your computer and use it in GitHub Desktop.
Save omeinusch/5557123 to your computer and use it in GitHub Desktop.
Currency-filter for Django's template engine
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