0
我正在研究一個玩具web框架,並且我實現了一個redirect_to方法來將用戶重定向到指定的URL。下面的代碼使用WSGIref的重定向
def _redirect_to(_self, _url):
"""Takes an url as argument and returns a location header"""
return ([('Location', _url)], "") # --- (i)
返回的元組,然後由應用程序處理的,這裏的代碼
...
else:
status = '200 OK'
params['_GET'] = get_data(_environment)
params['_POST'] = post_data(_environment)
(headers, response) = objview(objcontroller, _params = params) # tuple from (i) is stored here
_start_response(status, headers)
但是它無法正常工作。以下是我的瀏覽器正在接收的標題:
Content-Length:0
Date:Thu, 19 Jul 2012 06:03:52 GMT
Location:http://google.com
Server:WSGIServer/0.1 Python/2.7.3
頭部有什麼問題嗎?
乾杯,
UTSAV
你的重定向回覆的狀態代碼是什麼?如果它如上面的代碼所示是200,這是錯誤的。重定向是通過「位置」標頭**和** 302(找到)狀態碼完成的。 – math 2012-07-19 07:47:27
它的工作!謝謝。 – Utsav 2012-07-19 09:44:25