开发者

Deleting inline-code from html

I'm using the inline-app from Django-Basic-Apps for inserting images in Blogposts. But in some templates I don't want the images to appear. It's not enough to just not render them, I don't even want the inline-code to be in the html. Is there a way to delete the inline-code with a filter? I tried to use the "|cut" filter, but its just not flexible enough. I guess I would have to write my own templatetag to take care of this, but I'm quite new to Pytho开发者_如何学运维n and Django and don't now how that works.


If anybody's interested, here is my solution:

@register.filter
def del_inlines(value):

    soup = BeautifulStoneSoup(value, selfClosingTags=['inline'])
    inlines = soup.findAll('inline')
    [inline.extract() for inline in inlines]
    return soup

BeautifulSoup is just great!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜