Skip errors in Django using HttpResponseRedirect

I know that HttpResponseRedirect accepts only one parameter - the URL. But there are cases when I want to redirect with the display of an error message.

I read this post: How to pass information using HTTP redirection (in Django) , and there were a lot of good suggestions. I really don't want to use a library that I don't know how it works. I do not want to rely on posts that, according to Django docs, will be deleted. I was thinking about using sessions. I also like the idea of ​​passing it to a URL, for example:

return HttpResponseRedirect('/someurl/?error=1')

and then with some code from the error code to the message. Is it good practice to have a global structure similar to a map that hardcodes these error messages or is there a better way?

Or do I just need to use a session

EDIT: I worked using the session. Is it really good practice to be busy with this?

+3
source share
1 answer

You are correct in auth messages. They are deprecated, but as docs suggest you use the django framework messages , which I think is the exact soul for your business.

+9
source

Source: https://habr.com/ru/post/1783327/


All Articles