Gaurav Gaurav - 4 months ago 8
CSS Question

Want to display the first character of word in django templates

I want to display first character of user in django templates.
I want to make a image of user first character like caption or avatar

like this https://meta.discourse.org/t/switch-from-gravatar-to-html-css-letters-for-no-avatar-users/15336

<p>{{postone.user}}</p>


so i will get result like any name "Gaurav" or "Amit" but i just want first letter of them like "G" or "A"
So i can display it like image of first letter.

Answer

Solution with using templates tags(but for me the answer from @Kasra more preferable):

First letter:

{{ postone.user|make_list|first }}

Word without first:

{{ postone.user|make_list|slice:'1:'|join:'' }}