we are using a context_processor.

e.g., the view for a login-page could look like this:

        if everythins is ok:
                request.session['messages'] = ['message', 'You are logged in.']
                return HttpResponseRedirect(referer)
        else:
                 messages = ['error', 'Some error message.']

and then, you can use a context_processor:

TEMPLATE_CONTEXT_PROCESSORS = (
     ....
     'www.views.context_processors.get_messages',
)

get_messages could look like this (get_messages checks the session  
and returns a message-dict):

def get_messages(request):

     messages = []
     if request.session.get('messages'):
         messages = [request.session['messages'][0], request.session 
['messages'][1]]
         del request.session['messages']

     return {
         'messages': messages,
     }

patrick


Am 27.07.2007 um 08:57 schrieb Michael Lake:

>
> Hi all
>
> Nis Jørgensen wrote:
>> The argument to HttpResponseRedirect is a url. You seem to be  
>> confusing
>> it with a template.
>
> OK I can do this:
>
>       code ....
>       # some error occurs
>       message = 'You have ... tell admin that ....'
>       return HttpResponseRedirect('error/')
>
> and have in views.py
>
> def error(request, message):
> {
>    return render_to_response('error_page.html', {'message':message})
> }
>
> But how to get the message into error() without passing it as a GET?
>
>> If you want to display different content, you need
>> to pass a different url or (not recommended) store the data you  
>> want to
>> display, then display it to the user at the new url
>
>> But if you have the data available, there is no reason to do a  
>> redirect.
>> Just render the error message etc to the relevant template, then  
>> return
>> that to the user.
>
> Why I dont want to pass it like this ?message='You have ... tell  
> admin that ....'
> is that its long and if the error is something like main?delete=100  
> but the user cant
> delete that id then a Redirect goes to a nice clean valid URL.
> A render_to_response leaves the incorrect URL in the browser.
>
> Mike
> -- 
>
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to