Repository: Pylons/pyramid

Issue:
Update Hello World example to align with TryPyramid.com
We've updated the Hello World example on https://trypyramid.com per https://github.com/Pylons/trypyramid.com/pull/205 so we should update it on our official docs.

Verify that line numbers and narrative still align in docs whenever a `literalinclude` of Python files occurs.

- [x] README.rst
- [x] docs/designdefense.rst
- [x] docs/index.rst
- [x] docs/narr/helloworld.py
- [x] docs/narr/hellotraversal.py (take care to adapt code)
- [x] docs/narr/configuration.rst ("Declarative Configuration" section only)
- [x] docs/narr/firstapp.rst
- [x] docs/narr/hellotraversal.rst
- [x] docs/quick_tour/hello_world/app.py
- [x] docs/quick_tour.rst ("Hello World" section only)

Note that I excluded `docs/quick_tutorial/*` because it deliberately starts with imperative configuration, then introduces declarative configuration in [Step 7](http://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/views.html).


Discussion:
Will completing the list above also include whatever source file is used to generate text on https://pypi.python.org/pypi/pyramid? Or is there another file that needs modifying?
Good catch. I've added `README.rst` to the list.
I wanted to get some opinions before working on this issue. Below are two examples where the differences are:

1. **usage of the `request` object** - I think using the `request` object in the README.rst example is interesting and educational, but it's not "minimal". I'm leaning toward using the `request` object.
2. **port number** - I'd like to change the port number from 8080 to 6543 throughout examples because that's what is used by the cookiecutters and most of the documentation and for consistency.

# TryPyramid.com

```python
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    return Response('Hello World!')  # does NOT make use of the request object

if __name__ == '__main__':
    with Configurator() as config:
        config.add_route('hello', '/')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 6543, app)
    server.serve_forever()
```

# README.rst
```python
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response

def hello_world(request):
    return Response('Hello %(name)s!' % request.matchdict)  # makes use of the request object

if __name__ == '__main__':
    with Configurator() as config:
        config.add_route('hello', '/hello/{name}')
        config.add_view(hello_world, route_name='hello')
        app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8080, app)
    server.serve_forever()
```
TryPyramid.com has the authoritative version. It's simpler and requires fewer changes to the port number throughout our documentation.

Resolving patch:
diff --git a/docs/narr/hellotraversal.py b/docs/narr/hellotraversal.py
--- a/docs/narr/hellotraversal.py
+++ b/docs/narr/hellotraversal.py
@@ -2,21 +2,24 @@
 from pyramid.config import Configurator
 from pyramid.response import Response
 
+
 class Resource(dict):
     pass
 
+
 def get_root(request):
     return Resource({'a': Resource({'b': Resource({'c': Resource()})})})
 
+
 def hello_world_of_resources(context, request):
     output = "Here's a resource and its children: %s" % context
     return Response(output)
 
+
 if __name__ == '__main__':
-    config = Configurator(root_factory=get_root)
-    config.add_view(hello_world_of_resources, context=Resource)
-    app = config.make_wsgi_app()
-    server = make_server('0.0.0.0', 8080, app)
+    with Configurator() as config:
+        config.set_root_factory(get_root)
+        config.add_view(hello_world_of_resources, context=Resource)
+        app = config.make_wsgi_app()
+    server = make_server('0.0.0.0', 6543, app)
     server.serve_forever()
-
-
diff --git a/docs/narr/helloworld.py b/docs/narr/helloworld.py
--- a/docs/narr/helloworld.py
+++ b/docs/narr/helloworld.py
@@ -4,12 +4,13 @@
 
 
 def hello_world(request):
-    return Response('Hello %(name)s!' % request.matchdict)
+    return Response('Hello World!')
+
 
 if __name__ == '__main__':
     with Configurator() as config:
-        config.add_route('hello', '/hello/{name}')
+        config.add_route('hello', '/')
         config.add_view(hello_world, route_name='hello')
         app = config.make_wsgi_app()
-    server = make_server('0.0.0.0', 8080, app)
+    server = make_server('0.0.0.0', 6543, app)
     server.serve_forever()
diff --git a/docs/quick_tour/hello_world/app.py b/docs/quick_tour/hello_world/app.py
--- a/docs/quick_tour/hello_world/app.py
+++ b/docs/quick_tour/hello_world/app.py
@@ -4,7 +4,7 @@
 
 
 def hello_world(request):
-    return Response('<h1>Hello World!</h1>')
+    return Response('Hello World!')
 
 
 if __name__ == '__main__':


Test patch: