当前位置:网站首页>Realization of topic function
Realization of topic function
2022-07-28 06:14:00 【Ke Yulong】
I believe everyone knows the topic , For example, the topic of Weibo , Click the topic to show all posts under the topic


The main technology stack is to replace the topic with a hyperlink tag that can be clicked
The following code shows (python,tornado Framework implementations )>>>>>>>>
# Regular substitution
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:
# Replace topic
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 sublistThis code , Using the idea of packaging , Encapsulate the replacement as a method , In order to call , Reduce code reuse !
After replacement, the front end will use the obtained replacement content v-html Convert to label , Click the hyperlink to get the specified tag id, To get all the content under this tab !
There are many similar ones that need to be replaced ,@ The same principle applies to friends , Interested partners can try
边栏推荐
- 基于tensorflow搭建神经网络
- 《On Low-Resolution Face Recognition in the Wild:Comparisons and New Techniques》低分辨率人脸识别论文解读
- 3: MySQL master-slave replication setup
- Wechat applet development and production should pay attention to these key aspects
- Deep learning (incremental learning) -- iccv2021:ss-il: separated softmax for incremental learning
- Differences between processes and threads
- 深度学习(自监督:SimCLR)——A Simple Framework for Contrastive Learning of Visual Representations
- Deep learning (II) into machine learning and deep learning programming
- D2SC-GAN:基于双深浅通道生成对抗网络的课堂场景低分辨率人脸识别
- Transformer's understanding
猜你喜欢

TensorFlow2.1基本概念与常见函数

UNL class diagram

强化学习——策略学习

循环神经网络

How to do wechat group purchase applet? How much does it usually cost?

Four perspectives to teach you to choose applet development tools?

《AdaFace: Quality Adaptive Margin for Face Recognition》用于人脸识别的图像质量自适应边缘损失

小程序开发解决零售业的焦虑

Reinforcement learning - Strategic Learning

transformer的理解
随机推荐
将项目部署到GPU上,并且运行
基于选择性知识提取的野外低分辨率人脸识别的论文阅读笔记
强化学习——策略学习
Deep learning (self supervision: Moco V2) -- improved bases with momentum contractual learning
On low resolution face recognition in the wild:comparisons and new technologies
一、语音合成与自回归模型
Four perspectives to teach you to choose applet development tools?
Deep learning (self supervision: simple Siam) -- Exploring simple Siamese representation learning
知识点21-泛型
What are the general wechat applet development languages?
循环神经网络
NLP project actual custom template framework
2: Why read write separation
Knowledge point 21 generic
Which is more reliable for small program development?
First meet flask
Deep learning (incremental learning) -- iccv2021:ss-il: separated softmax for incremental learning
Word2vec+ regression model to achieve classification tasks
flutter webivew input唤起相机相册
深度学习——Patches Are All You Need