代码基本上都是按照那本封面是狗的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!!!
添加回答
举报
0/150
提交
取消