我一直在使用Django消息框架,但是由于某种原因,它不会在我使用Django 1.7构建的这个新应用程序上显示任何消息。这是我的配置......
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
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.request',
'django.contrib.messages.context_processors.messages',
)
{% if messages %}
<div class="alert alert-success">
<ul class="messages">
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% block content %}
{% endblock content %}
INSTALLED_APPS = (
'grappelli',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
@login_required(login_url='/')
def skills(request, template_name):
user = request.user
try:
skills = Skills.objects.get(user=user)
credit_options = CreditOptions.objects.filter(credit=user.credit_set.get())
except Skills.DoesNotExist:
messages.success(request, "Let's create a skills profile before you begin.")
return redirect(urlresolvers.reverse('add_skills'))
return render(request, template_name, {
'user': user,
'credit_options': credit_options
})
我不太确定从哪里开始。有什么建议吗?
答案 0 :(得分:-1)
你试过了吗?
messages.add_message(request, messages.SUCCESS,
"Let's create a skills profile before you begin.")