简体   繁体   中英

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.

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:'' }}

试试<p>{{ postone.user.first_name.0 }}</p>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM