为了账号安全,请及时绑定邮箱和手机立即绑定

python flask遇到'NoneType' object is not subscriptable错误

python flask遇到'NoneType' object is not subscriptable错误

吃鸡游戏 2019-02-23 19:05:36
代码基本上都是按照那本封面是狗的flask书敲的 @users.before_app_request def before_request(): if current_user.is_authenticated: current_user.ping() if not current_user.confirmed \ and request.endpoint[:5] != 'user.': return redirect(url_for('user.unconfirmed')) 这段出错的代码也反复对比好几次,跟书上一样啊。。。。百度也搜不到是什么问题 下面是报错信息:求指点 builtins.TypeError TypeError: 'NoneType' object is not subscriptable Traceback (most recent call last) This is the Copy/Paste friendly version of the traceback. You can also paste this traceback into a gist: Traceback (most recent call last): File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2301, in __call__ return self.wsgi_app(environ, start_response) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2287, in wsgi_app response = self.handle_exception(e) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1733, in handle_exception reraise(exc_type, exc_value, tb) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\_compat.py", line 35, in reraise raise value File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2284, in wsgi_app response = self.full_dispatch_request() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1807, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1710, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\_compat.py", line 35, in reraise raise value File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 1803, in full_dispatch_request rv = self.preprocess_request() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\flask\app.py", line 2079, in preprocess_request rv = func() File "D:\exercises\blog\app\views\users.py", line 70, in before_request and request.endpoint[:5] != 'user.': TypeError: 'NoneType' object is not subscriptable
查看完整描述

1 回答

?
Qyouu

TA贡献1786条经验 获得超11个赞

你把错误翻译一下,结合debug大约你就可见:

request.endpoint[:5]

这里的这个

request.endpoint

很可能为None,然后print(request.endpoint)看看结果,诶,卧槽!果然为None!!!

查看完整回答
反对 回复 2019-03-01
  • 1 回答
  • 0 关注
  • 1833 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信