Django custom filter working in dev but not in prod
I created a custom template filter in django at myapp/templatetags/custom_filters.py
.
@register.filter(name='indian_number_format')
def indian_number_format(value):
"""
Format the number in Indian style using the locale module (e.g., 1,00,00,000).
"""
if not isinstance(value, (int, float, Decimal)):
print('Not a number', type(value))
return value
try:
# Set the locale to Indian (Hindi)
locale.setlocale(locale.LC_NUMERIC, 'hi_IN')
# Format the number using locale formatting
formatted_value = locale.format_string("%d", value, grouping=True)
return formatted_value
except locale.Error:
# Fallback in case the locale is not available on the system
return value
Using it in template like this
{% extends "base.html" %}
{% load custom_filters %}
<p>{{number|indian_number_format}}</p>
For example, if the number is 123456
, the output should be 1,23,456
and this works fine in dev but the commas do not appear in prod which I have hosted on AWS. Any insight on what might be causing this issue would be helpful. Thanks.