Last active

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

  • Download Gist
1 2 3 4 5 6 7 8
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='!/search?q=\g<ht>' target='_blank'>\g<ht></a>",
re.sub(r"@(?P<un>([a-zA-Z0-9_]){1,15})", r"@<a href='\g<un>' target='_blank'>\g<un></a>", value))

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.