不确定这是 django 问题还是 python 问题。我试图通过从返回多个值的函数中接受值来使缓存工作。
目前页面在heavy_view函数上给了我这个错误:“'NoneType'对象不可迭代”
有没有办法让“counter,college_user,name_college_list = cache.get(cache_key)”行工作?然后检查它是否为空。谢谢!
#Views.py
def filter_results():
#some code here
return counter, college_user, name_college_List
def heavy_view(request):
cache_key = 'facebookcache'
cache_time = 180 # time to live in seconds
counter, college_user, name_college_list = cache.get(cache_key)
if not cache.get(cache_key):
result = filter_results() # some calculations here
cache.set(cache_key, result, cache_time)
return result