[Answer]-Django templates decimal separator with safe tag

1πŸ‘

βœ…

I don’t think you problem is in any way connected to using safe. It’s just a case of python string formating (that you use in your view) not being location-aware. You could try using locale.format() instead, which is intended as a locale-aware alternative.

But it is not a good practice to put HTML into your views anyway. So I would move formating logic to your template:

view.py

def a(request)
  a=3.222
  c=1.555
  content={'a':b, 'c':c}
  return render(request, 'a.html', context)

a.html

{% if a>5 %}
    <b>{{ a }}</b>
{% else %}
    {{ a }}
{% endif %}

{{ c }}

Leave a comment