Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $YECBGYFECGEAFWHA as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2

Deprecated: imwpcache\f884414bce24ee67f\f73723ec7b1919fa5::__construct(): Implicitly marking parameter $BBWFDDBHHYHDXXAB as nullable is deprecated, the explicit nullable type must be used instead in /www/wwwroot/www.chuangxiangniao.com/wp-content/plugins/imwpcache-dist/build/f884414bce24ee67ff73723ec7b1919fa5.php on line 2
Flask-Login 属性访问报错:如何解决“str’ object has no attribute ‘id’”?_创想鸟

Flask-Login 属性访问报错:如何解决“str’ object has no attribute ‘id’”?

flask-login 属性访问报错:如何解决“str' object has no attribute 'id'”?

flask-login属性访问报错

使用flask-login进行用户登录时,遇到了无法获取登录用户的属性问题,报错为:“str’ object has no attribute ‘id’”(字符串对象没有id属性)。

问题原因:
初始化user类时,将数据库模型中的user对象直接传入,而不是获取相应属性值。

解决方法:
在user类中正确获取数据库模型的属性值。修改后的代码如下:

class User(UserMixin):    def __init__(self, user_id):        self.id = user_id.id        self.name = user_id.name

此外,使用current_user.name获取用户名称时,也应确保数据库中存在“name”字段。

以上就是Flask-Login 属性访问报错:如何解决“str’ object has no attribute ‘id’”?的详细内容,更多请关注创想鸟其它相关文章!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1353422.html

赞 (0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
如何用Python绘制十二瓣花?
上一篇 2025年12月13日 17:40:37
使用 Flask-Login 登录时,如何正确获取数据库模型中用户的属性?
下一篇 2025年12月13日 17:40:47

相关推荐

发表回复

登录后才能评论
关注微信