我正在开发我的第一个 Flask 应用程序。直接从中取出一些代码,我试图确保用户的 cookie 中存在一个值。
def after_this_request(f):
if not hasattr(g, 'after_request_callbacks'):
g.after_request_callbacks = []
g.after_request_callbacks.append(f)
return f
@app.after_request
def call_after_request_callbacks(response):
for callback in getattr(g, 'after_request_callbacks', ()):
response = callback(response)
return response
@app.before_request
def detect_unique_id():
unique_id = request.cookies.get('unique_id')
if unique_id is None:
unique_id = generate_unique_id()
@after_this_request
def remember_unique_id(response):
response.set_cookie('unique_id', unique_id)
g.unique_id = unique_id
我不断收到此错误:
Traceback (most recent call last):
File "/..../env/lib/python2.7/site-packages/flask/app.py", line 1701, in __call__
return self.wsgi_app(environ, start_response)
File "/..../env/lib/python2.7/site-packages/flask/app.py", line 1690, in wsgi_app
return response(environ, start_response)
TypeError: 'NoneType' object is not callable
我试图了解此错误的原因。请帮忙。