Michael Lake skrev:
> 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?
>
As others have said, you can stuff things into request.session (after
adding the right middleware incantations).
>> 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.
What is so bad about leaving the url in the browser? I assume the error
message you display is the "correct" response for that url. Just
remember to add the correct status code - probably 400,403 or 404. Note
that if this is a GET url, it shouldn't have side effects, so your
"main?delete=100" example seems like a bad idea to begin with (unless
this is the page that shows an "Are you sure ...?" message). If it is a
POST, there is a lot of reason not to redirect it, since this will make
it harder for the user to use the back button to fix things.
Nis Jorgensen
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---