Include a URL in a Django template tag

x.x.x

New Member
I'm building a Django blog app, since that's apparently what all the cool kids are doing. I've built a template tag to display only the beginning of the post if it's long, and ideally to include a link to the whole post. I started looking into escaping and IsSafe=True, but my worry is that the content itself could have HTML tags in it that could mess things up. Here's what I have now:\[code\]@register.filter(name='shorten')def shorten(content): #will show up to the first 500 characters of the post content if len(content) > 500: return content[:500] + '...' + <a href="http://stackoverflow.com/entry/{{post.id}}">(cont.)</a> else: return content\[/code\]
 
Back
Top