我最近升级到 Django 1.3,我想开始使用 Messages 系统。
我已将中间件、模板上下文处理器和消息添加到INSTALLED_APPS
MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
'facebook.djangofb.FacebookMiddleware',
'annoying.middlewares.RedirectMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
"django.contrib.messages.context_processors.messages",
)
INSTALLED_APPS = (
'django.contrib.messages',
)
我只是根据进行简单计算的视图进行测试。
在管理员中,会显示消息,但是当尝试在我的 base.html 文件中呈现它们时,出现以下错误。
Caught TypeError while rendering: 'module' object is not iterable
在堆栈中它在这里失败了。
{% for message in messages %}
我还删除了 for 语句,但我仍然收到以下错误,仅此而已
<module 'django.contrib.messages' from '/Users/ApPeL/.virtualenvs/mysite.com/lib/python2.7/site-packages/django/contrib/messages/__init__.py'>
有任何想法吗?