V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
yakczh
V2EX  ›  问与答

SQLAlchemy 从数据库读出纪录怎么输出 json

  •  
  •   yakczh · Dec 30, 2014 · 4302 views
    This topic created in 4147 days ago, the information mentioned may be changed or developed.
    照http://simplectic.com/blog/2014/flask-todomvc-sqlalchemy/ 上面的例子 要对每个表字段挨个配置一遍
    def to_json(self):
    return {
    "id": self.id,
    "title": self.title,
    "order": self.order,
    "completed": self.completed}

    def from_json(self, source):
    if 'title' in source:
    self.title = source['title']
    if 'order' in source:
    self.order = source['order']
    if 'completed' in source:
    self.completed = source['completed']
    除了这种方式,还有别的简单一点的办法吗?
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3388 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 10:44 · PVG 18:44 · LAX 03:44 · JFK 06:44
    ♥ Do have faith in what you're doing.