LoginSignup
1
1

More than 5 years have passed since last update.

web2pyのモデルに辞書を挿入

Posted at

こういうモデルがあった場合

models/db.py
db = DAL('sqlite://storage.sqlite')
db.define_table(
    'name',
    Field('first'),
    Field('last'))

辞書を挿入したい場合こうする

controllers/default.py
name = dict(first='taro', last='qiita')
try:
    db.name.insert(**name)
except:
    db.rollback()
else:
    db.commit()

当初、以下のコードを実行できなくて詰まったのでメモした。

name = dict(first='taro', last='qiita')
# ...
db.name.insert(name)
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1