Saturday, April 9, 2011

My success messages are not returned

Hello!
I need return a "message success" to my list view, but the message not
appears on html page.

This is my function edit:

from django.shortcuts import redirect

def edit(request, object_id):
if request.method == 'POST':
e = Emprego.objects.get(pk=object_id)
form = EditForm(request.POST, instance=e)
if form.is_valid():
form.save()
messages.success(request, 'Vaga alterada com sucesso!.')
<-- here is the message
return redirect('/vagas/lista') <-- here is the redirect
else:
vaga = Emprego.objects.get(pk=object_id)
form = EditForm(instance=vaga)
return render_to_response('vagas/edit.html', {'form': form})

I put configurations on settings.py:

MIDDLEWARE_CLASSES
'django.contrib.messages.middleware.MessageMiddleware',

TEMPLATE_CONTEXT_PROCESSORS
'django.contrib.messages.context_processors.messages',

INSTALLED_APPS
'django.contrib.messages',

And put this code in html page to view the message success:

{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}
>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}

Anyone know why not working? No message is displayed. =/

Thanks!! =)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment