flask 数据库增删改查(flask 27)

2019-08-13 14:41:33 浏览数 (1)

create note=Note() db.session.add(note) db.session.commit()

query: Note.query.all()/first()/get(id)/count()/first_or_404()/get_or_404(id)/paginate()

过滤方法: Note.query.filter(Note.body='SHAVE').first() Note.queyr.filter_by(body='SHAVE').first() order_by() limit(5) group_by() offset(5)

模糊搜索: filter_by(body.like('�ff%')) filter_by(body.in_(['a','b','c'])) filter_by(~body.in_(['a','b','c'])) :not in filter_by(body=xx,title=xxx) :and filter_by(or_(body=xx,title=xxx)) :or

update: 直接修改 db.session.commit()

delete: db.sesssion.delete(xx) db.session.commit()


flash(xxx) {% for message in get_flashed_messages()%} {% endfor %}

shell上下文: @app.shell_context_processor def make_shell_context(): return dict(db=db,Note=note)

0 人点赞