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!
精彩评论