RequestStack middleware

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
class RequestStackMiddleware(object):
    '''
    Keeps track of the last 3 succesful requests
    '''
    def process_response(self, request, response):
        if 'requeststack' not in request.session:
            request.session['requeststack'] = ['/', '/', request.path]
        else:
            if request.method == 'GET' and 'text/html' in response.headers['Content-Type']:
                stack = request.session['requeststack']
                stack = stack[1:] # remove the first item
                stack.append(request.path)
                request.session['requeststack'] = stack
        
        return response

In a view:
    return HttpResponseRedirect(request.session['requeststack'][-1]) # or -2 or -3

More like this

  1. Ignore HTTP Accept-Language headers by fonso 6 years, 1 month ago
  2. CurrentSessionIDMiddleware by troolee 2 years, 11 months ago
  3. Middleware to detect visitors who arrived from a search engine by exogen 6 years, 1 month ago
  4. Cookieless Session Middleware by juliocarlos 4 years, 6 months ago
  5. Upload, Progressbar with sessions by revolunet 4 years, 10 months ago

Comments

(Forgotten your password?)