在python字典中使用current_user变量?

赛义夫·卡齐

我正在尝试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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Rails的devise中使用“ current_user”?

来自分类Dev

何时在控制器中使用current_user

来自分类Dev

在邮件程序中使用设计方法“ current_user”

来自分类Dev

在设计中使用 current_user 选择用户名

来自分类Dev

使用devise存根current_user

来自分类Dev

使用current_user的Rails服务对象

来自分类Dev

不能在jinja2宏中使用current_user?

来自分类Dev

如何在Rake Task Rails中使用current_user方法

来自分类Dev

Flask-Login中使用current_user的这种方法安全吗?

来自分类Dev

您可以在rails中的current_user中使用肮脏的属性方法吗?

来自分类Dev

为订单使用未定义的局部变量或方法“ current_user”

来自分类Dev

Rails:未定义的本地变量或方法“ current_user”

来自分类Dev

current_user和@current_user(我正在使用devise)有什么区别?

来自分类Dev

不使用current_user的correct_user吗?

来自分类Dev

使用无会话设计时current_user是什么?

来自分类Dev

.current_user在使用范围时不起作用?

来自分类Dev

如何使用current_user自动分配评论者?

来自分类Dev

在Python中使用变量值作为字典/类名

来自分类Dev

在Rails控制器中访问devise current_user变量

来自分类Dev

在Rails 3中从application.js访问current_user变量

来自分类Dev

未定义的局部变量或方法“ current_user”可以

来自分类Dev

为什么子线程无法访问flask_login中的current_user变量?

来自分类Dev

未定义的局部变量或方法`current_user'cancancan

来自分类Dev

Rails 4 has_many:through关联:在其他父模型中使用devise current_user在after_create回调中

来自分类Dev

在ApplicationController中设计current_user = nil

来自分类Dev

Rspec。如何测试current_user方法

来自分类Dev

涉及current_user的Rails定制验证

来自分类Dev

Current_user &&用户个人资料

来自分类Dev

Devise的current_user不起作用?

Related 相关文章

  1. 1

    如何在Rails的devise中使用“ current_user”?

  2. 2

    何时在控制器中使用current_user

  3. 3

    在邮件程序中使用设计方法“ current_user”

  4. 4

    在设计中使用 current_user 选择用户名

  5. 5

    使用devise存根current_user

  6. 6

    使用current_user的Rails服务对象

  7. 7

    不能在jinja2宏中使用current_user?

  8. 8

    如何在Rake Task Rails中使用current_user方法

  9. 9

    Flask-Login中使用current_user的这种方法安全吗?

  10. 10

    您可以在rails中的current_user中使用肮脏的属性方法吗?

  11. 11

    为订单使用未定义的局部变量或方法“ current_user”

  12. 12

    Rails:未定义的本地变量或方法“ current_user”

  13. 13

    current_user和@current_user(我正在使用devise)有什么区别?

  14. 14

    不使用current_user的correct_user吗?

  15. 15

    使用无会话设计时current_user是什么?

  16. 16

    .current_user在使用范围时不起作用?

  17. 17

    如何使用current_user自动分配评论者?

  18. 18

    在Python中使用变量值作为字典/类名

  19. 19

    在Rails控制器中访问devise current_user变量

  20. 20

    在Rails 3中从application.js访问current_user变量

  21. 21

    未定义的局部变量或方法“ current_user”可以

  22. 22

    为什么子线程无法访问flask_login中的current_user变量?

  23. 23

    未定义的局部变量或方法`current_user'cancancan

  24. 24

    Rails 4 has_many:through关联:在其他父模型中使用devise current_user在after_create回调中

  25. 25

    在ApplicationController中设计current_user = nil

  26. 26

    Rspec。如何测试current_user方法

  27. 27

    涉及current_user的Rails定制验证

  28. 28

    Current_user &&用户个人资料

  29. 29

    Devise的current_user不起作用?

热门标签

归档