django 最简单获取文章摘要方法
使用re模块,把所有的html标签去除,然后取文章前300个字符作为文章摘要
import re html='欢迎来到<a href="http://www.chenxm.cc">陈新明</a>,Python博客' pattern = re.compile(r'<[^>]+>',re.S) description = pattern .sub('',html) print(description[:300] ) # 欢迎来到陈新明,Python博客