Reputation:
I have this problem I've been trying to tackle for a while. I have a variable that is 17 characters long, and when displaying the variable on my form, I want it to display the last seven characters of this variable in bold...how do I go about this...I'd really appreciate anybody's insight on this.
Upvotes: 0
Views: 231
Reputation: 881555
{{ thevar|slice:":-7" }}<b>{{ thevar|slice:"-7:" }}</b>
The slice
built-in filter in Django templates acts like slicing does in Python, so that for example s[:-7]
is the string excluding its last 7 characters and s[-7:]
is the substring formed by just the last 7 characters.
Upvotes: 2