Gre*_*reg 15 python django django-templates django-settings
我试图建立一个像本文提到的模板上下文处理器,以便我可以为每个模板提供信息.
我在views.py中写了这个函数:
def items_in_cart(request):
"""Used by settings.TEMPLATE_CONTEXT_PROCESSORS to provide an item count
to every template"""
cart, lines = get_users_cart_and_lines(request)
return {'items_in_cart': lines.count()}
Run Code Online (Sandbox Code Playgroud)
然后我将此行添加到settings.py:
TEMPLATE_CONTEXT_PROCESSORS = ('Store.views.items_in_cart',)
Run Code Online (Sandbox Code Playgroud)
但现在每当我去任何页面时都会收到此错误:
ImproperlyConfigured at /
Put 'django.contrib.auth.context_processors.auth' in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.
Run Code Online (Sandbox Code Playgroud)
我做错什么了吗?这里发生了什么?我尝试做错误所说的内容,然后它将呈现一个页面,其中包含我的所有样式表和图像.
PiG*_*GeH 21
Django有一组默认的TEMPLATE_CONTEXT_PROCESSORS,您需要在添加自己的时手动添加.http://docs.djangoproject.com/en/1.3/ref/settings/#template-context-processors
根据您的Django版本,这些是不同的,但是如果使用Django 1.3,您可能会有以下内容
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.contrib.messages.context_processors.messages",
"Store.views.items_in_cart",
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10013 次 |
| 最近记录: |