当我尝试运行模板上下文处理器时,我得到“超出最大递归深度”。
settings.py看起来像这样:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.core.context_processors.media',
'django.core.context_processors.static',
'cms.context_processors.media',
'sekizai.context_processors.sekizai',
'web.context_content.base_context',
)
网/ context_content.py:
from web import models
from django.shortcuts import render
from django.shortcuts import render_to_response
from django.template import RequestContext
#from django.conf import settings
def base_context(request):
categories = models.Category.objects.filter()
return render(request, "base.html", {'categories':categories})
不知道为什么我会遇到这样一个奇怪的错误
更新:我的urls.py(网站):
from django.conf.urls.defaults import *
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings
from django.contrib.auth.views import login, logout
from web import views
from web import forms
admin.autodiscover()
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^register/$', views.register),
url(r'^login/$', views.login),
#url(r'^index/$', include('web.urls'))
url(r'^', include('cms.urls'))
)
if settings.DEBUG:
urlpatterns = patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns
我没有使用我的应用程序的urls.py来做任何事情。但无论如何它在这里:
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
from django.conf.urls import patterns, include, url
from web import views
from web import forms
admin.autodiscover()
urlpatterns = patterns('web.views',
#url(r'^', views.base_context),
)
答案 0 :(得分:1)
我不确定您要使用该上下文处理器做什么。它们用于向模板上下文添加项目,并且应始终返回字典:但由于某种原因,您在函数内部渲染模板。由于上下文处理器由渲染快捷方式调用,因此您的函数最终会调用自身,因此无限递归。
不要在上下文处理器中渲染模板。