1

我在我的项目中构建了一个小应用程序,旨在遍历给定的文本并提取带有 # 标记的单词。

当接收到英文文本时,它可以正常工作,但是当使用阿拉伯语或中文时,它就不起作用了。知道如何使它也适应外语吗?

在我的model.py中我写了

class Article(models.Model):

def _strip_hash_tags(self, ):
    return tuple([tag.strip("#") for tag in self.content.split() if tag.startswith("#")])

def save(self, force_insert=False, force_update=False, using=None):
    super(Article, self).save(force_insert=force_insert, force_update=force_update, using=using)

    # first remove all associatd tags with object
    Tag.objects.remove_all_tags(self)
    # then, look through content field and insert all tagged words
    for tag in self._strip_hash_tags():
        Tag.objects.add_tag(self, tag)
4

0 回答 0