Google云者 = Google Cloud Platform 学习者
现在注册
已注册用户请 登入
Google云者  ›  V2EX

修改新浪微博图片显示问题

By life at 2 years, 7 months ago, 509 hits
因新浪微博的图片地址改变策略,原代码无法支持,修改如下:

v2ex\templatetags\filters.py

原为:

# auto convert *.sinaimg.cn/*/*.jpg and bcs.baidu.com/*.jpg links to image tags
def sinaimg(value):
imgs = re.findall('(http://ww[0-9]{1}.sinaimg.cn/[a-zA-Z0-9]+/[a-zA-Z0-9]+.[a-z]{3})\s?', value)
for img in imgs:
value = value.replace(img, '<a href="' + img + '" target="_blank"><img src="' + img + '" class="imgly" border="0" /></a>')
baidu_imgs = re.findall('(http://(bcs.duapp.com|img.xiachufang.com|i.xiachufang.com)/([a-zA-Z0-9\.\-\_\/]+).jpg)\s?', value)
for img in baidu_imgs:
value = value.replace(img[0], '<a href="' + img[0] + '" target="_blank"><img src="' + img[0] + '" class="imgly" border="0" /></a>')
return value
register.filter(sinaimg)

修改为:

# auto convert *.sinaimg.cn/*/*.jpg and bcs.baidu.com/*.jpg links to image tags
def sinaimg(value):
imgs = re.findall('(http://w[a-zA-Z0-9]{2}.sinaimg.cn/[a-zA-Z0-9]+/[a-zA-Z0-9]+.[a-z]{3})\s?', value)
for img in imgs:
value = value.replace(img, '<a href="' + img + '" target="_blank"><img src="' + img + '" class="imgly" border="0" /></a>')
baidu_imgs = re.findall('(http://(bcs.duapp.com|img.xiachufang.com|i.xiachufang.com)/([a-zA-Z0-9\.\-\_\/]+).jpg)\s?', value)
for img in baidu_imgs:
value = value.replace(img[0], '<a href="' + img[0] + '" target="_blank"><img src="' + img[0] + '" class="imgly" border="0" /></a>')
return value
register.filter(sinaimg)
目前尚无回复

CC BY-NC 4.0 - Google云者:Google Cloud Platform Leaner