我想在我的Django 1.11项目中使用Memcached。我使用的是Python 3.6。 我已经在我的mac OSX终端上用Homebrew安装了memcached。之后我安装了它的python绑定:
pip install python-memchached==1.58
然后我将必要的配置添加到我的settings.py项目文件中:
CACHES = {
'default': {
'BACKEND':'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION':'127.0.0.1:11211',
}
}
我有两个终端,一个用于我的本地主机,另一个用于memcached:
memcached -l 127.0.0.1:11211
当我刷新我的网页时,我收到以下错误:
System check identified no issues (0 silenced).
October 15, 2017 - 10:47:30
Django version 1.11.6, using settings 'educa.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Internal Server Error: /
Traceback (most recent call last):
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/utils.py", line 65, in __getitem__
return self._engines[alias]
KeyError: 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/backends/django.py", line 126, in
get_package_libraries
module = import_module(entry[1])
File
"/Users/comp/Desktop/Dev/educa/lib/python3.6/importlib/__init__.py",
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in
_find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in
exec_module
File "<frozen importlib._bootstrap>", line 205, in
_call_with_frames_removed
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/memcache_status/templatetags/memcache_status_tags.py", line
3, in <module>
from django.core.cache import get_cache
ImportError: cannot import name 'get_cache'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/core/handlers/base.py", line 217, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/core/handlers/base.py", line 215, in _get_response
response = response.render()
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/response.py", line 107, in render
self.content = self.rendered_content
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/response.py", line 82, in rendered_content
template = self.resolve_template(self.template_name)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/response.py", line 64, in resolve_template
return select_template(template, using=self.using)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/loader.py", line 44, in select_template
engines = _engine_list(using)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/loader.py", line 72, in _engine_list
return engines.all() if using is None else [engines[using]]
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/utils.py", line 89, in all
return [self[alias] for alias in self]
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/utils.py", line 89, in <listcomp>
return [self[alias] for alias in self]
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/utils.py", line 80, in __getitem__
engine = engine_cls(params)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/backends/django.py", line 30, in __init__
options['libraries'] = self.get_templatetag_libraries(libraries)
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/backends/django.py", line 48, in
get_templatetag_libraries
libraries = get_installed_libraries()
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/backends/django.py", line 113, in
get_installed_libraries
for name in get_package_libraries(pkg):
File "/Users/comp/Desktop/Dev/educa/lib/python3.6/site-
packages/django/template/backends/django.py", line 130, in
get_package_libraries
"trying to load '%s': %s" % (entry[1], e)
django.template.library.InvalidTemplateLibrary: Invalid template
library specified. ImportError raised when trying to load
'memcache_status.templatetags.memcache_status_tags': cannot import
name 'get_cache'
[15/Oct/2017 10:47:33] "GET / HTTP/1.1" 500 131841
有人能指出我解决问题的方法吗?