Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django templates, find string replace with other string

Hay, I'm writing some templates but I want to convert " " into "_" within a string.

I want to convert the output of

{{ user.name }} 

from something like "My Name" to "My_Name". How do I do this?

like image 406
dotty Avatar asked Feb 02 '10 15:02

dotty


1 Answers

A shorter version of Matthijs' answer:

{{ user.name.split|join:"_" }} 

Of course it only works when splitting on whitespace.

like image 125
daniel Avatar answered Oct 01 '22 00:10

daniel