Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example tornado script doesn't work #38

Open
moradology opened this issue Oct 16, 2014 · 2 comments
Open

Example tornado script doesn't work #38

moradology opened this issue Oct 16, 2014 · 2 comments

Comments

@moradology
Copy link

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

@mission-liao
Copy link
Contributor

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.

@moradology
Copy link
Author

Beautiful. I'm very excited to play around with restless - thank you for your contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants