You cannot get context variables from an HttpResponseRedirect . It doesn't make sense why you set context variables if you redirect anyway.
You should certainly be able to select variables from the session after the redirect. I did this in several of my tests. How do you approve session data in a test case?
Here's how I talk about asserting session variables after a redirect:
response = self.client.post(reverse('foo')) self.assertRedirects(response, reverse('bar', args = ['baz']), status_code = 302, target_status_code = 200) self.assertEqual('value', self.client.session.get('key'))
Self.client is an instance of django.test.client.Client in this case.
Update
(In response to @Marconi's comment) Here is one way to display a message to a user after a redirect. This is copied almost verbatim from my answer to another question .
Your first view can create a message for the current one using auth, and the second read will read and delete it. Something like that:
def first_view(request, *args, **kwargs): # all goes well message = _("<message for user>") request.user.message_set.create(message = message) return redirect('second_view') def second_view(request, *args, **kwargs): # Render page # Template for second_view: {% for message in messages %} ... {% endfor %}
Messages are stored in the database. This means that you can access them even after redirecting. They are automatically read and deleted when the template is rendered. You will need to use RequestContext .
Manoj govindan
source share