@register.assignment_tag()<EOL>def convert_currency(amount, from_currency, to_currency):
try:<EOL><INDENT>rate = CurrencyRate.objects.get(<EOL>from_currency__iso_code=from_currency,<EOL>to_currency__iso_code=to_currency)<EOL><DEDENT>except CurrencyRate.DoesNotExist:<EOL><INDENT>return _('<STR_LIT>')<EOL><DEDENT>try:<EOL><INDENT>history = rate.history.all()[<NUM_LIT:0>]<EOL><DEDENT>except IndexError:<EOL><INDENT>return _('<STR_LIT>')<EOL><DEDENT>return amount * history.value<EOL>
Converts currencies.

Example:
{% convert_currency 2 'EUR' 'SGD' as amount %}