0

I want to display images according to the user's first and second letter from the username  instead of an image with rounded corners. But

<div> {{Post.author.username.0} } </div>

Returns only the first letter instead. Please help, how do I return 2 letters for example: Ahmed as Ah instead of A.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
Jude Iloeh
  • 11
  • 2

1 Answers1

1

You can use the |slice template filter [Django-doc] to construct a substring with the first two characters:

{{ Post.author.username|slice:":2" }}
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555