Skip to content

Commit

Permalink
Consistently format the three "Hello, world" examples (docs and README)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
gward committed Jun 21, 2015
1 parent fdfaf3d commit 5039d3d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
12 changes: 7 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions docs/guide/structure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5039d3d

Please sign in to comment.