Didina Deen Didina Deen - 16 days ago 5
Python Question

'dict' object has no attribute 'HTTP_REFERER'

I've been trying to find the previous url following this answer:

Django request to find previous referrer

So, in my .py I did:

print request.META
print request.META.HTTP_REFERER
print request.META['HTTP_REFERER']


request.META returns:

{'RUN_MAIN': 'true', 'HTTP_REFERER': 'http://127.0.0.1:8000/info/contact/', 'XDG_GREETER_DATA_DIR': '/var/lib/lightdm-data/user', 'QT4_IM_MODULE': 'xim',....


So, I can see HTTP_REFERER is there, but when trying to access it either way I get the error:

<type 'exceptions.AttributeError'>
'dict' object has no attribute 'HTTP_REFERER'


How can I access it?

Answer

I would suggest:

request.META.get('HTTP_REFERER')
Comments