Last pages the user visited

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

class LastVisitedMiddleware(object):
    """This middleware sets the last visited url as session field"""

    def process_request(self, request):
        """Intercept the request and add the current path to it"""
        request_path = request.get_full_path()
        try:
            request.session['last_visited'] = request.session['currently_visiting']
        except KeyError:
            # silence the exception - this is the users first request
            pass

        request.session['currently_visiting'] = request_path

More like this

  1. YUI Loader as Django middleware by akaihola 3 years, 9 months ago
  2. Remember path decorator by robhudson 2 years, 2 months ago
  3. Current Page Middleware by brutasse 1 year, 7 months ago
  4. Persistent Session Debugging with Django Debug Toolbar by brianjaystanley 3 months, 3 weeks ago
  5. Effective content caching for mass-load site using redirect feature by nnseva 7 months ago

Comments

derivin (on May 22, 2007):

Question: What about REFERER_URL on the HTTP header? This should work for the translation problem and any page where you require that the request is coming from a link on your site. If the REFERER is not from your site, you need to handle that differently.

This is how the login_required system works, and it works for tabbed browsers, as they maintain the REFERER information separately per tab/click.

Granted this will not work for when a user browses to a different site, and then back again, or closes the browser and returns.

#

mocara (on May 23, 2007):

The problem with REFERER_URL is that a lot of (stupid) firewall apps remove headers such as this and even ACCEPTS!?! For security/privacy reasons.

I found this out when I realised that people using zone_alarm had slow loads times. Zone_alarm cuts out ACCEPTS which means the server won't send gzip content. What ACCEPTS has to do with your security I have no idea.

#

Leonidas (on May 28, 2007):

Using referrer would be a nice solution, if it would work effectively. Another solution could be a combination of both referrer and my middleware. If the referrer would not give useful results (being stripped or whatever) my middleware could still be used.

Anyway, thanks for pointing out, I forgot this way to go.

#

(Forgotten your password?)