Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Template: remove underscore and capitalize each word

Is there any filter in Django that can remove underscores and also capitalize each letter of the word OR remove underscores and capitalize the first letter of sentence?

like image 330
Romaan Avatar asked Dec 19 '25 08:12

Romaan


1 Answers

@register.filter()
def field_name_to_label(value):
    value = value.replace('_', ' ')
    return value.title()
like image 171
Zoie Avatar answered Dec 22 '25 02:12

Zoie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!