我想在python燒瓶框架中得到HTTP_REFERER
。 我的路線是這樣的:request.environ ['HTTP_REFERER']是無
@app.route('/login')
def login():
if authenticateForPanel():
return redirect(url_for("panel"))
else:
ref = request.environ['HTTP_REFERER']
return render_template('login.html',blogOptions = g.blogOptions,ref=ref)
當我執行此,我得到KeyError: 'HTTP_REFERER'
與回溯:
Traceback (most recent call last):
File "/Users/ozcan/flask/flask/app.py", line 1823, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/ozcan/flask/flask/app.py", line 1811, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/ozcan/flask/flask/app.py", line 1809, in wsgi_app
response = self.full_dispatch_request()
File "/Users/ozcan/flask/flask/app.py", line 1482, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/ozcan/flask/flask/app.py", line 1480, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/ozcan/flask/flask/app.py", line 1466, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/ozcan/Documents/python/app.py", line 318, in login
ref = request.environ['HTTP_REFERER']
KeyError: 'HTTP_REFERER'
當我第一次寫這個代碼是working.I不直接調用此網址。我打電話localhost:5000/panel
,它將我重定向到login
方法。所以基本上應該有一個引用者,我錯了嗎?
當我打印的request.environ['HTTP_REFERER']
它打印None
我也試圖與
ref = request.referrer
但None
爲什麼它可以發生?非常感謝。
檢查一下我打印裁判變量終端 – saidozcan 2013-02-18 16:48:22
抱歉,但一切都沒有改變 – saidozcan 2013-02-18 16:49:11
你的意思是你添加打印語句和運行服務器。如果您仍然收到上述例外情況,則不能重新啓動服務器。除非對象沒有這樣的方法,get方法不會引發異常EVER。 – 2013-02-18 16:51:13