From b1b92284f496800a4dfd2cea72cb9be07ba8661c Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 16:52:14 -0400 Subject: First cut at import of quick tutorial. --- docs/quick_tutorial/hello_world.rst | 111 ++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 docs/quick_tutorial/hello_world.rst (limited to 'docs/quick_tutorial/hello_world.rst') diff --git a/docs/quick_tutorial/hello_world.rst b/docs/quick_tutorial/hello_world.rst new file mode 100644 index 000000000..e44ef616d --- /dev/null +++ b/docs/quick_tutorial/hello_world.rst @@ -0,0 +1,111 @@ +================================ +01: Single-File Web Applications +================================ + +What's the simplest way to get started in Pyramid? A single-file module. +No Python packages, no ``setup.py``, no other machinery. + +Background +========== + +Microframeworks are all the rage these days. "Microframework" is a +marketing term, not a technical one. They have a low mental overhead: +they do so little, the only things you have to worry about are *your +things*. + +Pyramid is special because it can act as a single-file module +microframework. You can have a single Python file that can be executed +directly by Python. But Pyramid also provides facilities to scale to +the largest of applications. + +Python has a standard called :term:`WSGI` that defines how +Python web applications plug into standard servers, getting passed +incoming requests and returning responses. Most modern Python web +frameworks obey an "MVC" (model-view-controller) application pattern, +where the data in the model has a view that mediates interaction with +outside systems. + +In this step we'll see a brief glimpse of WSGI servers, WSGI +applications, requests, responses, and views. + +Objectives +========== + +- Get a running Pyramid web application, as simply as possible + +- Use that as a well-understood base for adding each unit of complexity + +- Initial exposure to WSGI apps, requests, views, and responses + +Steps +===== + +#. Make sure you have followed the steps in :doc:`python_setup`. + +#. Create a directory for this step: + + .. code-block:: bash + + (env27)$ mkdir hello_world; cd hello_world + +#. Copy the following into ``hello_world/app.py``: + + .. literalinclude:: hello_world/app.py + :linenos: + +#. Run the application: + + .. code-block:: bash + + (env27)$ python app.py + +#. Open ``http://localhost:6543/`` in your browser. + +Analysis +======== + +New to Python web programming? If so, some lines in module merit +explanation: + +#. *Line 11*. The ``if __name__ == '__main__':`` is Python's way of + saying "Start here when running from the command line". + +#. *Lines 12-14*. Use Pyramid's :term:`pyramid:configurator` to connect + :term:`pyramid:view` code to a particular URL + :term:`pyramid:route`. + +#. *Lines 6-7*. Implement the view code that generates the + :term:`pyramid:response`. + +#. *Lines 15-17*. Publish a :term:`pyramid:WSGI` app using an HTTP + server. + +As shown in this example, the :term:`pyramid:configurator` plays a +central role in Pyramid development. Building an application from +loosely-coupled parts via :ref:`pyramid:configuration_narr` is a +central idea in Pyramid, one that we will revisit regularly in this +*Quick Tour*. + +Extra Credit +============ + +#. Why do we do this: + + .. code-block:: python + + print ('Starting up server on http://localhost:6547') + + ...instead of: + + .. code-block:: python + + print 'Starting up server on http://localhost:6547' + +#. What happens if you return a string of HTML? A sequence of integers? + +#. Put something invalid, such as ``print xyz``, in the view function. + Kill your ``python app.py`` with ``cntrl-c`` and restart, + then reload your browser. See the exception in the console? + +#. The ``GI`` in ``WSGI`` stands for "Gateway Interface". What web + standard is this modelled after? \ No newline at end of file -- cgit v1.2.3 From 4042c772c8043ac96a22db439a736fec9ea2aafa Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 17:09:35 -0400 Subject: All the references re-wired. --- docs/quick_tutorial/hello_world.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'docs/quick_tutorial/hello_world.rst') diff --git a/docs/quick_tutorial/hello_world.rst b/docs/quick_tutorial/hello_world.rst index e44ef616d..e3ad820ac 100644 --- a/docs/quick_tutorial/hello_world.rst +++ b/docs/quick_tutorial/hello_world.rst @@ -70,19 +70,19 @@ explanation: #. *Line 11*. The ``if __name__ == '__main__':`` is Python's way of saying "Start here when running from the command line". -#. *Lines 12-14*. Use Pyramid's :term:`pyramid:configurator` to connect - :term:`pyramid:view` code to a particular URL - :term:`pyramid:route`. +#. *Lines 12-14*. Use Pyramid's :term:`configurator` to connect + :term:`view` code to a particular URL + :term:`route`. #. *Lines 6-7*. Implement the view code that generates the - :term:`pyramid:response`. + :term:`response`. -#. *Lines 15-17*. Publish a :term:`pyramid:WSGI` app using an HTTP +#. *Lines 15-17*. Publish a :term:`WSGI` app using an HTTP server. -As shown in this example, the :term:`pyramid:configurator` plays a +As shown in this example, the :term:`configurator` plays a central role in Pyramid development. Building an application from -loosely-coupled parts via :ref:`pyramid:configuration_narr` is a +loosely-coupled parts via :ref:`configuration_narr` is a central idea in Pyramid, one that we will revisit regularly in this *Quick Tour*. -- cgit v1.2.3 From 0a784868bdbc3a0eb226ed00e8d89cda9d181ec5 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Fri, 13 Sep 2013 17:11:42 -0400 Subject: Fix naming of virtualenv prefix. --- docs/quick_tutorial/hello_world.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/quick_tutorial/hello_world.rst') diff --git a/docs/quick_tutorial/hello_world.rst b/docs/quick_tutorial/hello_world.rst index e3ad820ac..36ffe9d1e 100644 --- a/docs/quick_tutorial/hello_world.rst +++ b/docs/quick_tutorial/hello_world.rst @@ -46,7 +46,7 @@ Steps .. code-block:: bash - (env27)$ mkdir hello_world; cd hello_world + (env)$ mkdir hello_world; cd hello_world #. Copy the following into ``hello_world/app.py``: @@ -57,7 +57,7 @@ Steps .. code-block:: bash - (env27)$ python app.py + (env)$ python app.py #. Open ``http://localhost:6543/`` in your browser. -- cgit v1.2.3 From b0b28ede912c817a62a84b97c332e39eda02d166 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 16 Sep 2013 02:14:53 +0200 Subject: s/env/venv just for sake of consistency --- docs/quick_tutorial/hello_world.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/quick_tutorial/hello_world.rst') diff --git a/docs/quick_tutorial/hello_world.rst b/docs/quick_tutorial/hello_world.rst index 36ffe9d1e..09982ca66 100644 --- a/docs/quick_tutorial/hello_world.rst +++ b/docs/quick_tutorial/hello_world.rst @@ -46,7 +46,7 @@ Steps .. code-block:: bash - (env)$ mkdir hello_world; cd hello_world + (venv)$ mkdir hello_world; cd hello_world #. Copy the following into ``hello_world/app.py``: @@ -57,7 +57,7 @@ Steps .. code-block:: bash - (env)$ python app.py + (venv)$ python app.py #. Open ``http://localhost:6543/`` in your browser. -- cgit v1.2.3 From d749bf4c987c4ab90bd5f89326e7d4059e4f47b3 Mon Sep 17 00:00:00 2001 From: Tshepang Lekhonkhobe Date: Mon, 16 Sep 2013 02:18:11 +0200 Subject: make example links clickable, for convenience --- docs/quick_tutorial/hello_world.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/quick_tutorial/hello_world.rst') diff --git a/docs/quick_tutorial/hello_world.rst b/docs/quick_tutorial/hello_world.rst index 09982ca66..0898265ef 100644 --- a/docs/quick_tutorial/hello_world.rst +++ b/docs/quick_tutorial/hello_world.rst @@ -59,7 +59,7 @@ Steps (venv)$ python app.py -#. Open ``http://localhost:6543/`` in your browser. +#. Open http://localhost:6543/ in your browser. Analysis ======== -- cgit v1.2.3 From 187104fd81418beeb51592913041d9751bafe08d Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Wed, 25 Sep 2013 09:27:43 -0400 Subject: Quick Tutorial: Improve the setup instructions (adapted from Steve Piercy's work), particularly for Windows. Change all the steps to use $VENV/bin prefixes on commands (don't presume that they have done source env/bin/activate). --- docs/quick_tutorial/hello_world.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/quick_tutorial/hello_world.rst') diff --git a/docs/quick_tutorial/hello_world.rst b/docs/quick_tutorial/hello_world.rst index 0898265ef..166f791fc 100644 --- a/docs/quick_tutorial/hello_world.rst +++ b/docs/quick_tutorial/hello_world.rst @@ -40,13 +40,13 @@ Objectives Steps ===== -#. Make sure you have followed the steps in :doc:`python_setup`. +#. Make sure you have followed the steps in :doc:`requirements`. #. Create a directory for this step: .. code-block:: bash - (venv)$ mkdir hello_world; cd hello_world + $ mkdir hello_world; cd hello_world #. Copy the following into ``hello_world/app.py``: @@ -57,7 +57,7 @@ Steps .. code-block:: bash - (venv)$ python app.py + $ $VENV/bin/python app.py #. Open http://localhost:6543/ in your browser. -- cgit v1.2.3 From 34e974e360184baef873da55f31379697e367f32 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Wed, 25 Sep 2013 12:08:33 -0400 Subject: Get pyramid_chameleon added to the quick tutorial, plus some other fixes for Python 3. --- docs/quick_tutorial/hello_world.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/quick_tutorial/hello_world.rst') diff --git a/docs/quick_tutorial/hello_world.rst b/docs/quick_tutorial/hello_world.rst index 166f791fc..59e088a31 100644 --- a/docs/quick_tutorial/hello_world.rst +++ b/docs/quick_tutorial/hello_world.rst @@ -42,7 +42,8 @@ Steps #. Make sure you have followed the steps in :doc:`requirements`. -#. Create a directory for this step: +#. Starting from your workspace directory + (``~/projects/quick_tutorial``), create a directory for this step: .. code-block:: bash -- cgit v1.2.3 From b731b5fca253d9d95b3307490aa585e194676c01 Mon Sep 17 00:00:00 2001 From: Paul Everitt Date: Thu, 26 Sep 2013 17:41:44 -0400 Subject: Quick Tour: shorten the setup part and point to Quick Tutorial Requirements for more explanation. Cross link each Quick Tour section with its Quick Tutorial match. --- docs/quick_tutorial/hello_world.rst | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/quick_tutorial/hello_world.rst') diff --git a/docs/quick_tutorial/hello_world.rst b/docs/quick_tutorial/hello_world.rst index 59e088a31..c7a8eaf5e 100644 --- a/docs/quick_tutorial/hello_world.rst +++ b/docs/quick_tutorial/hello_world.rst @@ -1,3 +1,5 @@ +.. _qtut_hello_world: + ================================ 01: Single-File Web Applications ================================ -- cgit v1.2.3