Created
November 4, 2014 08:36
-
-
Save mehmetkose/a11b11679c37b46a66e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.ioloop | |
import tornado.web | |
import logging | |
import motor | |
client = motor.MotorClient('mongodb://localhost:27017') | |
db = client.test_database | |
class MainHandler(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
def get(self): | |
db = self.settings['db'] | |
document = {'key': 'value'} | |
self.write("hellno world") | |
db.test_collection.insert(document, callback=self.my_callback) | |
def my_callback(self, result, error): | |
if error: | |
logging.error("wtf") | |
if result: | |
repr(result) | |
self.write("yea") | |
tornado.ioloop.IOLoop.instance().stop() | |
application = tornado.web.Application([ | |
(r"/", MainHandler), | |
], db=db) | |
if __name__ == "__main__": | |
application.listen(8888) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Jesse, I updated the code.