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 a Referer
header, and if one doesn't you will get exactly this exception. Test if the result of get()
is not None
to see if the header was sent.
Make this change to fix the key error:
referer = request.META.get('HTTP_REFERER', '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With