Skip to content

Instantly share code, notes, and snippets.

@kingbuzzman
Created February 17, 2011 20:49
Show Gist options
  • Select an option

  • Save kingbuzzman/832652 to your computer and use it in GitHub Desktop.

Select an option

Save kingbuzzman/832652 to your computer and use it in GitHub Desktop.
session refer.py
class MainsiteMiddleware(object):
def process_request(self, request):
from mainsite.urls import urlpatterns
current_path = request.META.get('PATH_INFO', '')
inside_mainsite = False
# loop over all the page of mainsite
for url in urlpatterns:
# check to see if there is a url match
if url.resolve(current_path[1:]) or url.resolve(current_path):
inside_mainsite = True
break
# if they are not in mainsite -- ignore
if not inside_mainsite:
return
# check to see if they have the referer set -- if not, set it
if 'HTTP_REFERER' not in request.session:
request.session['HTTP_REFERER'] = current_path
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment