Redirection using WSGIref

醉酒当歌 提交于 2019-12-12 00:33:16

问题


I am working on a toy web framework and I have implemented a method redirect_to for redirecting the user to a specified URL. Here the code

def _redirect_to(_self, _url):
  """Takes an url as argument and returns a location header"""

  return ([('Location', _url)], "")                   # --- (i)

The returned tuple is then handled by the app, here's the code

...
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)

However it is not working. Here are the headers that my browser is receiving:

Content-Length:0
Date:Thu, 19 Jul 2012 06:03:52 GMT
Location:http://google.com
Server:WSGIServer/0.1 Python/2.7.3

Is there something wrong with the headers ??

Cheers,

Utsav


回答1:


To do a HTTP redirection, you need both:

  • 'Location' HTTP header
  • '302 Found' HTTP status code

It seems that you are not changing the HTTP status code from 200 to 302.



来源:https://stackoverflow.com/questions/11554833/redirection-using-wsgiref

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!