]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Consistently format the three "Hello, world" examples (docs and README)
authorGreg Ward <greg@gerg.ca>
Sun, 21 Jun 2015 14:04:21 +0000 (10:04 -0400)
committerGreg Ward <greg@gerg.ca>
Sun, 21 Jun 2015 14:20:01 +0000 (10:20 -0400)
- encourage use of make_app() (makes testing easier)
- use fully-qualified module paths (painful in real-world code,
  but makes examples clearer)
- don't define a main() function that is never called: just
  use a boring old "__name__ == __main__" block, so the code
  can be copy + pasted + executed immediately
- just use a tuple when defining routes, not url(...): this is
  supposed to be a simple, minimalist example

README.rst
docs/guide/structure.rst
docs/index.rst

index 446e42bdf79f6bde8b3fcbe0163ea2f67bf1735c..cbe53f76b2b62ba06a0aecc341ef425e83152e6e 100644 (file)
@@ -41,13 +41,15 @@ Here is a simple "Hello, world" example web app for Tornado:
         def get(self):
             self.write("Hello, world")
 
-    application = tornado.web.Application([
-        (r"/", MainHandler),
-    ])
+    def make_app():
+        return tornado.web.Application([
+            (r"/", MainHandler),
+        ])
 
     if __name__ == "__main__":
-        application.listen(8888)
-        tornado.ioloop.IOLoop.instance().start()
+        app = make_app()
+        app.listen(8888)
+        tornado.ioloop.IOLoop.current().start()
 
 This example does not use any of Tornado's asynchronous features; for
 that see this `simple chat room
index 8527f4af66ae9be0737e58ed3bdf7c69978950f7..d8ad341f0b66aa983f1877b789fda44ae1c9cc80 100644 (file)
@@ -16,22 +16,22 @@ A minimal "hello world" example looks something like this:
 
 .. testcode::
 
-    from tornado.ioloop import IOLoop
-    from tornado.web import RequestHandler, Application, url
+    import tornado.ioloop
+    import tornado.web
 
-    class HelloHandler(RequestHandler):
+    class MainHandler(tornado.web.RequestHandler):
         def get(self):
             self.write("Hello, world")
 
     def make_app():
-        return Application([
-            url(r"/", HelloHandler),
-            ])
+        return tornado.web.Application([
+            (r"/", MainHandler),
+        ])
 
-    def main():
+    if __name__ == "__main__":
         app = make_app()
         app.listen(8888)
-        IOLoop.current().start()
+        tornado.ioloop.IOLoop.current().start()
 
 .. testoutput::
    :hide:
index aae707710b64cc202fed2b7a4add575179798967..52e653223996115d82c59b3e7f88b9782c7d9880 100644 (file)
@@ -40,12 +40,14 @@ Here is a simple "Hello, world" example web app for Tornado::
         def get(self):
             self.write("Hello, world")
 
-    application = tornado.web.Application([
-        (r"/", MainHandler),
-    ])
+    def make_app():
+        return tornado.web.Application([
+            (r"/", MainHandler),
+        ])
 
     if __name__ == "__main__":
-        application.listen(8888)
+        app = make_app()
+        app.listen(8888)
         tornado.ioloop.IOLoop.current().start()
 
 This example does not use any of Tornado's asynchronous features; for