Hi...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.
+2
A:
{{ 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.
Alex Martelli
2009-06-30 17:40:02
SWEET...didn't know this, though I knew there was some variable to do this
2009-06-30 17:50:05
Yeah, Django templating has a LOT of useful built-in tags and filters, and many map aspects of Python's functionality (though it's sometimes maddening for a Python programmer to remember "how do you say this in the Django templating language";-).
Alex Martelli
2009-06-30 18:03:15