我有一個使用 SQLite 資料庫的 Flask 應用程式。我創建了這個模型來將資料加載到資料庫中
class Category(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
products = db.Column(db.Text)
該資料庫已填充了大量資訊,我正在嘗試更改存盤資訊中字典中的特定變數。
# print 'products' for the first Category stored
x = Category.query.all()
xLoaded = json.loads(x[0].products)
print(xLoaded)
# output
[['test1', {'path': ['a', 'b', 'c']}], ['test2', {'path': ['d', 'e', 'f']}]]
具體來說,我正在嘗試改變'b','test1'所以我嘗試了這個:
x = Category.query.all()
xLoaded = json.loads(x[0].products)
xLoaded[0][1]['path'][1] = 'z'
db.session.commit()
然而,這并不能改變任何事情。
uj5u.com熱心網友回復:
該代碼僅更改變數的值,而xLoaded不是x.
改變變數的值x
x = Category.query.all()
xLoaded = json.loads(x[0].products)
xLoaded[0][1]['path'][1] = 'z'
x[0].products = xLoaded
db.session.commit()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/482459.html
標籤:Python 数据库 sqlite 烧瓶 烧瓶-sqlalchemy
上一篇:確定哪個路由將用于請求URL
下一篇:使用python燒瓶運行顫振
