If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

def index(): posts = db((db.post.id > 0).select(orderby=~db.post.dateline) #db.post hast a body-field

for post in posts:
    if len(post.body) > 1000:                            # Preview should be about 1000 chars
        index = post.body.find("</p>", 1000, -1) + 4     # find the index of the next </p> and add 4 chars
        post.body = post.body[0:index]                   # replace the body of the post post with short version

return dict(posts=posts)

Related slices

Comments (0)

Hosting graciously provided by:
Python Anywhere