You can save the previous page in a session variable before making the
redirect and then use it in the foo page.
--
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net
> Then in my html on the button that does the unlock I have something
> like this:
>
> <a href="{% url topic_unlock topic.id %}?next={% url post_list
> topic.id %}"
>
> I just thought maybe there was django magic that wouldn't require me
> to pass in the "next" url.
>
> Thanks for your insights!
If you want to avoid passing in a value through the template, you
could use boilerplate code such as the following in your view function
to inspect the HTTP_REFERER value in the HttpRequest object and
redirect or act accordingly:
from urlparse import urlsplit
referer = request.META.get('HTTP_REFERER', None)
if referer is None:
pass
# do something here
try:
redirect_to = urlsplit(referer, 'http', False)[2]
except IndexError:
pass
# do another thing here
return HttpResponseRedirect(redirect_to)
I have used something along the lines of that in view functions from
which I wanted users to be taken back to the page they were on when
they called the view.
--
Ayaz Ahmed Khan
An evil mind is a great comfort.