我想使用 Redis。所以我遵循了这个教程:https://github.com/sebleier/django-redis-cache
首先,我安装 redis-py:https://github.com/andymccurdy/redis-py/
然后,我将其放入我的设置中:CACHE_BACKEND = 'redis_cache.cache://localhost:6379'
然后我在我的 views.py 中这样做:
from redis_cache import cache #this imports just fine!
cache.set("haha","lala")
print cache.get("haha")
但出于某种原因,我得到一个 AttributeError:
Exception Type: AttributeError at /
Exception Value: 'module' object has no attribute 'set'
最佳答案
你想导入Django的缓存模块(最终调用Redis的抽象层)而不是直接使用Redis:
from django.core.cache import cache
关于python - 为什么我不能让 Django 与这个库对话?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4631719/