Pass errors in Django using HttpResponseRedirect
Posted
by
JPC
on Stack Overflow
See other posts from Stack Overflow
or by JPC
Published on 2011-01-04T02:21:55Z
Indexed on
2011/01/04
2:54 UTC
Read the original article
Hit count: 249
I know that HttpResponseRedirect only takes one parameter, a URL. But there are cases when I want to redirect with an error message to display.
I was reading this post: How to pass information using an http redirect (in Django) and there were a lot of good suggestions. I don't really want to use a library that I don't know how works. I don't want to rely on messages which, according to the Django docs, is going to be removed. I thought about using sessions. I also like the idea of passing it in a URL, something like:
return HttpResponseRedirect('/someurl/?error=1')
and then having some map from error code to message. Is it good practice to have a global map-like structure which hard codes in these error messages or is there a better way?
Or should I just use a session
EDIT: I got it working using a session. Is that a good practice to put things like this in the session?
© Stack Overflow or respective owner