public
Last active

twittify: django template filter to replace metions (@'s) and hashtags (#'s) with links to twitter

  • Download Gist
twittify.py
Python
1 2 3 4 5 6 7 8
@register.filter(name='twittify')
def twittify(value):
""" Replace @ and #'s with links to twitter"""
return mark_safe(
re.sub(r"#(?P<ht>([a-zA-Z0-9_])+)", r"#<a href='http://twitter.com/#!/search?q=\g<ht>' target='_blank'>\g<ht></a>",
re.sub(r"@(?P<un>([a-zA-Z0-9_]){1,15})", r"@<a href='http://twitter.com/\g<un>' target='_blank'>\g<un></a>", value))
)
twittify.mark_safe=True

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.