我正在尝试new_variable = current_user.pub
在字典中使用数据库中 pub 列中的数据,但出现此错误AttributeError: 'NoneType' object has no attribute 'pub'
非常感谢有关此问题的任何帮助
这是我的完整代码`
pins = {
4 : {'name' : 'Channel 1', 'board' : 'esp8266', 'topic' : '/4', 'state' : 'False'},
5 : {'name' : 'Channel 2', 'board' : 'esp8266', 'topic' : '/5', 'state' : 'False'}
}
variable = pins[4]['topic']
new_variable = current_user.pub
pins[4]['topic'] = new_variable
谢谢你
使用 python @property 装饰器在你的类中创建一个方法。并随心所欲地返回酒吧。
class User(db.Models):
id = db.Column(db.Integer, primary_key=True)
key = db.Column(db.String(80))
@property
def pub(self):
return "{}".format(self.key)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句