I have this view rendering a static page, but I cannot seem to catch the referer of the page.
def landing(request, referer='google'):
''' Loads the landing page '''
msg = ''
if request.method == 'GET':
referer = request.META['HTTP_REFERER']
return render_to_response('index.html',
{'WSGI_DIR': settings.WSGI_DIR,'csrf_value': get_token(request),
'referer':referer},context_instance=RequestContext(request))
It keeps popping:
KeyError at / ‘HTTP_REFERER’
I’ve imported everything needed. Does anyone have a clue?
You should be using
request.META.get('HTTP_REFERER'). Not every request will have aRefererheader, and if one doesn’t you will get exactly this exception. Test if the result ofget()is notNoneto see if the header was sent.