推荐学习书目
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 · Mar 4, 2014 · 3264 views
    This topic created in 4455 days ago, the information mentioned may be changed or developed.
    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 replies    1970-01-01 08:00:00 +08:00
    casparchen
        1
    casparchen  
       Mar 4, 2014
    Rs.query.filter_by(Rs.lb_id=lb_id).first()
    试试把Rs加上呢?
    tongle
        2
    tongle  
       Mar 14, 2014
    是sqlalchemy的版本问题吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3042 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 08:54 · PVG 16:54 · LAX 01:54 · JFK 04:54
    ♥ Do have faith in what you're doing.