I don't know if this is the best solution, but I made a
context_preocessor which add content from session variable to every
template i load. I then put in my layout a variable to show it. Finally,
every time I want to show some message i add it to a given variable in
session. Code for context processor looks like this:
def
flash(request):
#return {'flash': {'notice':
'works'}}
notice = request.session.get('flash_notice',
False)
request.session['flash_notice']=False
warning = request.session.get('flash_warning',
False)
request.session['flash_warning']=False
error = request.session.get('flash_error',
False)
request.session['flash_error']=False
#sprawdza czy sa w ogole jakiekolwiek
flashe
if notice or warning or
error:
messages =
True
else:
messages =
False
return {'flash': {'notice': notice, 'warning': warning, 'error':
error, 'messages':
messages}}
it checks for three types of messages: notice, warning and error. It
also add additional variable 'messages' to indicate if there is any
message to show at all. So, the only thing you need to do is add a
message to given session variable and reload/redirect a page. You can
read up on context processors and how to use them in django documentation.
Rodney Topor pisze:
> Suppose you've just processed posted form data and successfully added
> a new item to the database. Now you return HttpResponseRedirect('/
> items/') (I know, you should use a pattern name not an absolute URL
> here) to display the list of items, including the newly added item.
>
> But, suppose you want to prefix the list of items with a message,
> e.g., "Congratulations, your item was successfully added.". If you
> were returning render_to_response('item_list.html"), you could pass in
> a dictionary {"message": message}, and the template could display the
> variable message if it is not empty.
>
> How can you do something similar when using HttpResponseRedirect()?
>
> Or am I thinking about this problem the wrong way?
>
> Thanks.
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---