小细节

2018-01-21  本文已影响0人  马梦里
@main.route('/<string:id>')
def detail(id):
    m = Topic.find(id=id)
    u = current_user()
    return render_template("topic/detail.html", topic=m, user=u)

@classmethod
def find(cls, id):
    m = cls.one(id=id)
    m.views += 1
    m.save()
    return m

将浏览次数的增加包装成了类方法

def replies(self):
    from .reply import Reply
    ms = Reply.all(topic_id=self.id)
    return ms

在类方法里面,防止交叉引用:
from .reply import Reply

上一篇 下一篇

猜你喜欢

热点阅读