Python Django cache not working cached_querys()不接受任何参数(给定1个)

Python Django cache not working cached_querys()不接受任何参数(给定1个),python,django,templates,caching,Python,Django,Templates,Caching,我正在尝试在缓存中执行相同的查询,目前我正在使用我在这里找到的一个示例,但当我尝试打开模板时,出现了此错误 cached_queries() takes no arguments (1 given) Internal Server Error: /consulta-inicial/ Traceback (most recent call last): File "/home/gjce/.virtualenvs/medi1.8/local/lib/python2.7/site-package

我正在尝试在缓存中执行相同的查询,目前我正在使用我在这里找到的一个示例,但当我尝试打开模板时,出现了此错误

cached_queries() takes no arguments (1 given)



Internal Server Error: /consulta-inicial/
Traceback (most recent call last):
File "/home/gjce/.virtualenvs/medi1.8/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 164, in get_response
response = response.render()
File "/home/gjce/.virtualenvs/medi1.8/local/lib/python2.7/site-packages/django/template/response.py", line 158, in render
self.content = self.rendered_content
File "/home/gjce/.virtualenvs/medi1.8/local/lib/python2.7/site-packages/django/template/response.py", line 135, in rendered_content
content = template.render(context, self._request)
File "/home/gjce/.virtualenvs/medi1.8/local/lib/python2.7/site-packages/django/template/backends/django.py", line 74, in render
return self.template.render(context)
File "/home/gjce/.virtualenvs/medi1.8/local/lib/python2.7/site-packages/django/template/base.py", line 208, in render
with context.bind_template(self):
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/home/gjce/.virtualenvs/medi1.8/local/lib/python2.7/site-packages/django/template/context.py", line 241, in bind_template
updates.update(processor(self.request))
TypeError: cached_queries() takes no arguments (1 given)
这是我的密码

form.py

cie_4 = DropdownCie(cie_descripcion.objects.all().order_by('cie_descripcion_desc').order_by('cie_descripcion_desc'), required=False)
cache.set('cie1', cie_1)
设置.py

TEMPLATES = [
{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [PROJECT_DIR.child("templates")],
    'APP_DIRS': False,
    'OPTIONS': {
        'context_processors': [
            "expmedico.context_processors.cached_queries",
        ],
    },
},]
上下文处理器.py

from django.core.cache import cache

def cached_queries():
    return {'cache', cache.get('cie_1')}

正如错误所说,上下文处理器应该提供一个参数,而您没有。你的另一个问题是你返回的是一个集合,而不是一本字典。所有上下文处理器都应该返回一个字典{key:value,…},其中key是模板上下文中变量的名称,value是变量的值

def cached_queries(request):
    return {'cache': cache.get('cie_1')}

正如错误所说,上下文处理器应该提供一个参数,而您没有。你的另一个问题是你返回的是一个集合,而不是一本字典。所有上下文处理器都应该返回一个字典{key:value,…},其中key是模板上下文中变量的名称,value是变量的值

def cached_queries(request):
    return {'cache': cache.get('cie_1')}

除了接受参数外,上下文处理器还需要返回字典,而不是集合

def cached_queries(request):
    return {'cache': cache.get('cie_1')}

除了接受参数外,上下文处理器还需要返回字典,而不是集合

def cached_queries(request):
    return {'cache': cache.get('cie_1')}

你能编辑你的问题以包含完整的回溯吗?你能编辑你的问题以包含完整的回溯吗?是的,但如果我添加任何参数,如请求或自我,我会得到其他错误。无法将字典更新序列元素#0转换为sequence@MacAlexander这将是另一个错误(也是您应该发布的错误),因为文档明确指出上下文处理器应该“将请求对象作为其参数”。cache.get返回的是什么?查询集。。。cie_1=cie_descripion.objects.all().order_by('cie_descripion_desc')我编辑了我的答案,以显示您的第二个问题,但我应该感谢丹尼尔,他在我之前给出了他的答案。是的,但如果我添加任何参数,如request或self,我会得到其他错误。无法将字典更新序列元素#0转换为sequence@MacAlexander这将是另一个错误(也是您应该发布的错误),因为文档明确指出上下文处理器应该“将请求对象作为其参数”。cache.get返回的是什么?查询集。。。cie_1=cie_descripion.objects.all().order_by('cie_descripion_desc')我编辑了我的答案,以显示您的第二个问题,但我应该感谢丹尼尔,他在我之前给出了他的答案。