'dict' 对象没有属性 'HTTP_REFERER'

Did*_*een 4 python django dictionary

我一直在尝试在此答案之后找到以前的网址:

Django 请求查找以前的引用者

所以,在我的 .py 中我做了:

print request.META
print request.META.HTTP_REFERER
print request.META['HTTP_REFERER']
Run Code Online (Sandbox Code Playgroud)

request.META返回:

{'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',....
Run Code Online (Sandbox Code Playgroud)

所以,我可以看到 HTTP_REFERER 在那里,但是当我尝试以任何一种方式访问​​它时,我都会收到错误消息:

<type 'exceptions.AttributeError'>
'dict' object has no attribute 'HTTP_REFERER'
Run Code Online (Sandbox Code Playgroud)

我怎样才能访问它?

小智 6

我会建议:

request.META.get('HTTP_REFERER')
Run Code Online (Sandbox Code Playgroud)