tornado-rest-handler icon indicating copy to clipboard operation
tornado-rest-handler copied to clipboard

Better documentation is needed

Open beettlle opened this issue 11 years ago • 0 comments

I am trying to write a very basic front end to some data (retweet counts) I have in a DB and I can't get it to work. For now I've only written a basic skeleton of the code but even that doesn't work.

The code is this:

from tornado_rest_handler import routes, rest_routes

from python_rest_handler import DataManager
from tornado_rest_handler import TornadoRestHandler

import tornado.autoreload
import tornado.ioloop
import tornado.web

class ReTweetGraphData(DataManager):
    def instance_list(self): return []
    def find_instance_by_id(self, instance_id): pass
    def save_instance(self, data): pass
    def update_instance(self, instance, data): pass
    def delete_instance(self, instance): pass

class ReTweetGraphHandler(TornadoRestHandler):
    data_manager = ReTweetGraphData


TORNADO_ROUTES = [
    # another handlers here
    rest_routes(ReTweet, handler=ReTweetGraphHandler, prefix='retweet'),
    # another handlers here
]

TORNADO_SETTINGS = {}

application = tornado.web.Application(routes(TORNADO_ROUTES), **TORNADO_SETTINGS)
application.listen(8080)
ioloop = tornado.ioloop.IOLoop.instance()
tornado.autoreload.start(ioloop)
ioloop.start()

These are the errors I'm getting

  1. I get an error saying "ReTweet" is not defined. As far as I understand the example this is the name I want the entry point to be. When I change that to be the handler name "ReTweetGraphHandler" it seems to start up.
  2. When I try to hit the main index "/retweet" I'm getting a mongoengine error. I'm not sure how this code is getting to mongoengine as I though I overwrote that with my own "ReTweetGraphData" so I should be getting an empty array. The error looks like this:
ERROR:tornado.application:Uncaught exception GET /retweet (::1)
HTTPRequest(protocol='http', host='localhost:8080', method='GET', uri='/retweet', version='HTTP/1.1', remote_ip='::1', body='', headers={'Host': 'localhost:8080', 'Accept': '*/*', 'User-Agent': 'curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2'})
Traceback (most recent call last):
  File "/home/cdelgado/apps/twit/.twit-env/lib/python2.6/site-packages/tornado/web.py", line 1077, in _execute
    *self.path_args, **self.path_kwargs)
  File "/home/cdelgado/apps/twit/.twit-env/lib/python2.6/site-packages/tornado_rest_handler/trh.py", line 10, in get
    return self.rest_handler.get(instance_id=instance_id, edit=edit)
  File "/home/cdelgado/apps/twit/.twit-env/lib/python2.6/site-packages/python_rest_handler/prh.py", line 141, in get
    return self.page_list()
  File "/home/cdelgado/apps/twit/.twit-env/lib/python2.6/site-packages/python_rest_handler/prh.py", line 37, in page_list
    return self.render(self.handler.list_template, objs=self.handler.data_manager.instance_list(), alert=alert)
  File "/home/cdelgado/apps/twit/.twit-env/lib/python2.6/site-packages/python_rest_handler/data_managers/mongoengine.py", line 7, in instance_list
    return self.model.objects.all()
AttributeError: type object 'ReTweetGraphHandler' has no attribute 'objects'
ERROR:tornado.access:500 GET /retweet (::1) 5.08ms
  1. When I try to get something by value "/retweet/123123" I am getting a 404 error.
WARNING:tornado.access:404 GET /retweet/45345 (::1) 2.03ms

Maybe if this works it could be used to close out Issue #1

Thank you for any and all help

beettlle avatar Jul 28 '13 18:07 beettlle