restless
restless copied to clipboard
Example tornado script doesn't work
On my macbook pro, localhost:8001/pets throws a 500 with the example script for tornado.
Tested on python 2.7 and 3.4 - tornado and restless were the default pip installs on a fresh virtualenv as of 10/16/2014
You are right, that script didn't work and I missed to check validity of that example.
The right one should be something like this:
import tornado.ioloop
from tornado import web, gen
from restless.tnd import TornadoResource
class BaseHandler(web.RequestHandler):
def prepare(self):
""" do normal tornado preparation """
def initialize(self):
""" do your tornado initialization """
class PetResource(TornadoResource):
# bind BaseHandler instead of tornado.web.RequestHandler
_request_handler_base_ = BaseHandler
def __init__(self):
self.fake_db = [
{
"id": 1,
"name": "Mitti",
"type": "dog"
},
{
"id": 2,
"name": "Gary",
"type": "cat"
}
]
@gen.coroutine
def list(self):
raise gen.Return(self.fake_db)
routes = [
(r'/pets', PetResource.as_list()),
(r'/pets/([^/]+)', PetResource.as_detail())
]
app = web.Application(routes, debug=True)
if __name__ == '__main__':
app.listen(8001)
tornado.ioloop.IOLoop.instance().start()
I changed the way to integrate tornado.web.RequestHandler and didn't push changes back to this example, my bad. I will make a PR to this example later.
Beautiful. I'm very excited to play around with restless - thank you for your contributions