I want something similar to Twitter mentions that are turned into links but it is not working.
If we assume we have message = 'Do not forget to come with the Python book, @friend'
#function to convert @mentions to links
def mentions(message, username):
this_user_handle = reverse('mysite:profile', args=[username])
new_message = re.sub(r'(@\w+)', r"<a href= '#'>\g<0></a>", message)
new_message.replace('#', this_user_handle)
return new_message
mentions(message, 'yax') returns Do not forget to come with the Python book, <a href= '#'>@friend</a>'.
The # is not replaced and the new_message still displays as is in HTML page:
<p class= 'Post'>
{{ new_message|linebreaksbr}}
</p>
This displays this:
Do not forget to come with the Python book, <a href= '#'>@friend</a>'
Instead of:
Do not forget to come with the Python book, @friend
How do I get around this? Thank you in advance!