Пример #1
0
def add_query(id, username):
    """

    :param id:
    :param username:
    :return:
    """

    # 创建session对象:
    session = db_session()
    if not session.query(User).filter(User.id == id):
        print username, id
        # 创建新User对象:
        new_user = User(id=id, name=username)
        # 添加到session:
        session.add(new_user)
    # simple query
    user = session.query(User).filter(User.name == 'a').first()
    print user.id + user.name
    # 提交即保存到数据库:
    session.commit()
    # 关闭session:
    session.close()

    return render_template("index.html")
Пример #2
0
 def before_request():
     g.data_session = db_session()