I have a templatetags in my application that renders currency in my django templates
register = template.Library()
@register.filter
def currency(value):
try:
return "{:,.2f}".format(value)
except (ValueError, TypeError):
return value
@register.filter
def dollar_currency(value):
try:
return "${:,.2f}".format(value)
except (ValueError, TypeError):
return value
But when I use it on render_field on the template, it does not work.
It works for this {{form.sum_plan|currency}}
But does not work on this {% render_field formset.Jan_Plan|currency class="form-control" %}
A help will be highly appreciated.
Thanks.
There was no error, just that it rendered very well with {{form.sum_plan|currency}}, but not working with {% render_field formset.Jan_Plan|currency class=“form-control” %}
You can find in the upload. It rendered very well, showing the comma separation and the dollar sign, but in the textboxes rendered with render_field, it does not work.
There is no Django-provided tag named render_field, which means it’s part of a third-party package - something that you or someone else has written.
If you’re talking about the render_field tag provided by django-widget-tweaks, then the issue is that you’re rendering two different things here. A form widget is an input field, and its requirements are different than just rendering the value of a field.
What is going to control this is the type of form field widget being rendered, not the value being displayed in the field. (Also see Monetary amount input)
Yes it does. But when I apply render_field it doesn’t. I believe @KenWhitesell has said it all. It is not a Django-provided tag, it is a third party. I need to check what the third party provided, may be they are still working on it, but I need to check deeper. Thanks