python-flask 教程学习过程遇到难题TypeError: 'bool' object is not callable

qq_32104291 2015-12-11 05:47:11
http://www.oschina.net/translate/the-flask-mega-tutorial-part-vi-profile-page-and-avatars
在这个学习python-flask教程,下载源码运行的时候出现:TypeError: 'bool' object is not callable
错误代码:
@app.before_request

def before_request():

[Open an interactive python shell in this frame] g.user = current_user

if g.user.is_authenticated():

g.user.last_seen = datetime.utcnow()

db.session.add(g.user)

db.session.commit()

百度了好久没找到答案,初学,求解
...全文
5469 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_27713547 2017-11-18
  • 打赏
  • 举报
回复
今天也遇到了同样的问题,别人说is_authenticated是属性,所以有如下做法: models中的三个 def is_authenticated(self): return True def is_active(self): return True def is_anonymous(self): return False 改成 dis_authenticated = True is_active = True is_anonymous = False 然后将其他地方的is_authenticated()括号去掉,完美解决
AlvyHacker 2017-11-09
  • 打赏
  • 举报
回复
is_authenticated是属性而不是方法,把括号去掉就可以了。书里这一段有两处印刷错误,请参照git源码。
liqinzhe223 2017-10-17
  • 打赏
  • 举报
回复
楼上回复解决了我的问题!
zhanxueyou1 2016-04-13
  • 打赏
  • 举报
回复
关于 flask 中 Flask-Login中 if g.user is not None and g.user.is_authenticated(): TypeError: 'bool' object is not callable 我也跟着教程敲代码,Google老半天,结果在一篇俄国人的帖子中找的这个,https://plus.google.com/+MiguelGrinberg/posts/9o9idDfaYhK,尼玛,Miguel Grinberg这货说Flask-Login的0.3版本有问题,等他有时间再改,先用0.2.11。 好,果断换回旧版本: >pip uninstall Flask-Login >pip install -v Flask-Login==0.2.11 OK,再试试吧!

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧