Why is my redirect not working?

824 views
Skip to first unread message

bitcycle

unread,
Nov 2, 2012, 5:15:57 PM11/2/12
to python-...@googlegroups.com
Can someone here help me understand why these two different redirect methods are both failing?

Code

  1 #!/usr/bin/env python
  2
  3 import tornado.ioloop
  4 import tornado.web
  5
  6 class MainHandler(tornado.web.RequestHandler):
  7     def get(self):
  8         self.write("Hello, world")
  9
 10 class RedirectHandler(tornado.web.RequestHandler):
 11     def get(self):
 12         self.redirect('/', permanent = True)
 13
 14 handlers = list()
 15 handlers.append((r"/", MainHandler))
 16 handlers.append((r"/bar", RedirectHandler))
 17 handlers.append((r"/foo", tornado.web.RedirectHandler, dict(url='/')))
 18
 19 application = tornado.web.Application(handlers, debug = True)
 20 application.listen(8888)
 21 tornado.ioloop.IOLoop.instance().start()

Output

======================================================
[baseline]
curl localhost:8888/
Hello, world

======================================================
[redirect as custom handler]
curl localhost:8888/bar

======================================================
[redirect as builtin redirect handler]
curl localhost:8888/foo

======================================================

Russ Weeks

unread,
Nov 2, 2012, 5:26:33 PM11/2/12
to python-...@googlegroups.com
Tornado's working fine (although maybe safer to call self.finish in MainHandler.get).  Try curl -L to get curl to follow the redirect.

-Russ

bitcycle

unread,
Nov 2, 2012, 5:31:02 PM11/2/12
to python-...@googlegroups.com, rwe...@newbrightidea.com
Guess its a good thing that I posted the examples that I was testing with.  

Turns out the problem was how I was testing with curl.

Thanks Russ.
Reply all
Reply to author
Forward
0 new messages