当前位置:网站首页>话题功能实现
话题功能实现
2022-07-28 05:20:00 【可宇龙】
相信大家对话题都了解吧,比如微博的话题,点击话题展示该话题下的所有帖子


主要技术栈就是把话题替换为一个超链接标签可以点击
下面代码展示(python,tornado框架实现)>>>>>>>>
# 正则替换
async def change_object(self, sublist, stype):
re_dict = {
"talk": {"re": r'#([\w]+)#', "model": TalkModel, "column": "TalkModel.name.in_(items)",
"getkey": "myid.name", "replace": "#{}#", "a": "<a href='/talk?tid={}'>#{}#</a>"}
}
myre = re_dict[stype]["re"]
for x in sublist:
# 替换话题
items_dict = {}
items = re.findall(myre, x["content"])
ids = await self.database.execute(
re_dict[stype]["model"].select().where(eval(re_dict[stype]["column"])))
for myid in ids:
items_dict[eval(re_dict[stype]["getkey"])] = myid.id
for item in items:
try:
x["content"] = x["content"].replace(re_dict[stype]["replace"].format(item),
re_dict[stype]["a"].format(items_dict[item], item))
except Exception as e:
print(str(e))
pass
return sublist此代码,利用了封装的思路,将替换封装为一个方法,以便调用,减少代码的复用!
替换后前端将获取到的替换内容使用v-html转换为标签即可,通过点击超链接获取到指定标签id,来获取该标签下的所有内容!
类似这种需要替换的还有好多,@好友也是同样原理,感兴趣的小伙伴可以去试试
边栏推荐
猜你喜欢

基于php心理健康服务系统获取(php毕业设计)

结果填空 国庆有几天是星期日(纯Excel解决)

SVG了解与绘图应用

(php毕业设计)基于php小说网站管理系统获取

正则表达式

Review of metallurgical physical chemistry -- Fundamentals of metallurgical reaction kinetics and characteristics of multiphase reaction kinetics

Flex elastic box
![[uni app] the use of scroll into view in uni app](/img/34/475ef70416df7a92a52ba0efbc8947.png)
[uni app] the use of scroll into view in uni app

ArcMap中的距离工具条(Distance)

CMD and NPM basic commands
随机推荐
C语言走迷宫
基于php心理健康服务系统获取(php毕业设计)
设置滚动条
Cad-gis data conversion
命令注入绕过方式总结
Global event bus
基于php小区疫情出入管理系统(php毕业设计)
HDU-1284:钱币兑换问题 推理+动态规划(dp)
结果填空 购物单(教你用Excel解决)
ArcGIS Engine开发资源
南京邮电大学CTF题目writeup (二) 含题目地址
标准C语言总结4
初学移动端
ArcGIS地图制作的注记、格网添加
cmd和npm基础命令
(php毕业设计)基于php学生日常行为管理系统获取
ArcMap map map projection related operations
Books - social animals
media-搭建直播服务器
Zotero——一款文献管理工具