| | |
| | | The above ``helloworld.py`` script uses the following set of import statements: |
| | | |
| | | .. literalinclude:: helloworld.py |
| | | :linenos: |
| | | :lineno-match: |
| | | :lines: 1-3 |
| | | |
| | | The script imports the :class:`~pyramid.config.Configurator` class from the |
| | |
| | | ``hello_world``. |
| | | |
| | | .. literalinclude:: helloworld.py |
| | | :linenos: |
| | | :lineno-match: |
| | | :pyobject: hello_world |
| | | |
| | | The function accepts a single argument (``request``) and it returns an instance |
| | |
| | | statement: |
| | | |
| | | .. literalinclude:: helloworld.py |
| | | :linenos: |
| | | :lineno-match: |
| | | :lines: 9-15 |
| | | |
| | | Let's break this down piece by piece. |
| | |
| | | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| | | |
| | | .. literalinclude:: helloworld.py |
| | | :linenos: |
| | | :lineno-match: |
| | | :lines: 9-10 |
| | | |
| | | The ``if __name__ == '__main__':`` line in the code sample above represents a |
| | |
| | | another; the code within the ``if`` block should only be run during a direct |
| | | script execution. |
| | | |
| | | The ``config = Configurator()`` line above creates an instance of the |
| | | :class:`~pyramid.config.Configurator` class. The resulting ``config`` object |
| | | The ``with Configurator() as config:`` line above creates an instance of the |
| | | :class:`~pyramid.config.Configurator` class using a :term:`context manager`. The resulting ``config`` object |
| | | represents an API which the script uses to configure this particular |
| | | :app:`Pyramid` application. Methods called on the Configurator will cause |
| | | registrations to be made in an :term:`application registry` associated with the |
| | |
| | | ~~~~~~~~~~~~~~~~~~~~ |
| | | |
| | | .. literalinclude:: helloworld.py |
| | | :linenos: |
| | | :lineno-match: |
| | | :lines: 11-12 |
| | | |
| | | The first line above calls the :meth:`pyramid.config.Configurator.add_route` |
| | |
| | | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
| | | |
| | | .. literalinclude:: helloworld.py |
| | | :linenos: |
| | | :lineno-match: |
| | | :lines: 13 |
| | | |
| | | After configuring views and ending configuration, the script creates a WSGI |
| | |
| | | ~~~~~~~~~~~~~~~~~~~~~~~~ |
| | | |
| | | .. literalinclude:: helloworld.py |
| | | :linenos: |
| | | :lineno-match: |
| | | :lines: 14-15 |
| | | |
| | | Finally, we actually serve the application to requestors by starting up a WSGI |