Re: My success messages are not returned
Solved!
The problem is the "RequestContext", all views need this parameters on
return function, like this:
If I have this function "edit":
def edit(request, object_id):
#code here
return HttpResponseRedirect('/vagas/list')
My function "list" need this in return:
return render_to_response('vagas/list.html', {'lista':lista},
context_instance=RequestContext(request))
The key is -----> context_instance=RequestContext(request) in all
return's.
Thanks! =)
On 9 abr, 16:38, Guevara <eguevara2...@gmail.com> wrote:
> 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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home