honmaple
2016-10-23 14:27:53 +08:00
以前写过类似的功能
```
def at_user(self, content):
usernames = findall(r'@([\u4e00-\u9fa5\w\-]+)', content)
ex_usernames = []
for username in usernames:
user = User.query.filter_by(username=username).first()
if user is not None and username != current_user.username:
ex_usernames.append(user.username)
href = '/u/' + username
u = '@' + username + ' '
content = content.replace(u, '@<a href="%s">%s</a> ' %
(href, username))
usernames = list(set(ex_usernames))
return content, usernames
```