V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
cnupdog
V2EX  ›  Python

flask 使用 SQLAlchemy 问题求解释

  •  
  •   cnupdog · 2014-03-04 18:23:20 +08:00 · 2596 次点击
    这是一个创建于 3713 天前的主题,其中的信息可能已经有所发展或是发生改变。
    from flask.ext.sqlalchemy import SQLAlchemy

    是这样的,之前也一直没遇到,今天进行环境迁移后,发现有下面的问题,但不是每次都出现:

    ##插入数据
    rs_entity = Rs.query.filter_by(lb_id=lb_id).first()
    if rs_entity is not None:
    rs_entity.ip = vm['address']
    db.session.merge(rs_entity)
    db.session.commit()
    else:
    new_rs_entity = Rs(lb_id, vm['address'], 'inactive')
    db.session.add(new_rs_entity)
    db.session.commit()

    ##取数据
    rs_entity = Rs.query.filter_by(lb_id=lb_id).first() ---这里会报错,说找不到

    请问这个如何解析。
    2 条回复    1970-01-01 08:00:00 +08:00
    casparchen
        1
    casparchen  
       2014-03-04 19:32:03 +08:00
    Rs.query.filter_by(Rs.lb_id=lb_id).first()
    试试把Rs加上呢?
    tongle
        2
    tongle  
       2014-03-14 16:22:04 +08:00
    是sqlalchemy的版本问题吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2389 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 07:31 · PVG 15:31 · LAX 00:31 · JFK 03:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.