How do I pass template context information when using HttpResponseRedirect in Django?
django, http, python, redirect
Solution
The best way would probably be to use a coded querystring on the redirect URL... its an old school approach.
You could do something like
/page/?m=1, /page/?m=2, etc
You would then parse that variable with request.GET in the view code and show the appropriate message.
Problem
I have a form that redirects to the same page after a user enters information (so that they can continue entering information). If the form submission is successful, I'm returning ``` HttpResponseRedirect(request.path) ``` which works fine. However, I'd also like to display some messages to the user in this case (e.g., "Your data has been saved" at the top of the screen). If I weren't redirecting, I'd just return these messages in the context dictionary. With the redirect, however, I can't do this. So how can I pass template context information when using HttpResponseRedirect? What I'm trying to do seems like it would be incredibly common, so please excuse me if I'm missing something obvious.