【问题标题】:How come I can't get Django to talk to this library?为什么我不能让 Django 与这个库对话?
【发布时间】:2011-06-05 15:02:55
【问题描述】:

我想使用 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'

【问题讨论】:

    标签: python database django caching redis


    【解决方案1】:

    你想导入 Django 的缓存模块(最终调用 Redis 的抽象层)而不是直接使用 Redis:

    from django.core.cache import cache
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-05
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多