# decorators.py try: from functools import wraps except ImportError: from django.utils.functional import wraps # Python 2.3, 2.4 fallback. def remember_path(view_func): """ Decorator that stores the `request.path` URL in a session variable to be used later, e.g. in a "Continue Shopping" link on a cart page. """ def _wrapped_view_func(request, *args, **kwargs): request.session['last_path'] = request.path return view_func(request, *args, **kwargs) return wraps(view_func)(_wrapped_view_func) # views.py example to remember path @remember_path def shopping_view(request): # regular view code # views.py example to use path def cart_view(request): # view code return render_to_response('template.html', { 'last_path': request.session.get('last_path', '/'), # other context })