commit | author | age
|
558f3e
|
1 |
.. _qtut_cookiecutters: |
SP |
2 |
|
|
3 |
================================================= |
|
4 |
Prelude: Quick Project Startup with Cookiecutters |
|
5 |
================================================= |
|
6 |
|
f2520e
|
7 |
To ease the process of getting started on a project, the Pylons Project provides a :term:`cookiecutter` that generates sample :app:`Pyramid` projects from project templates. The cookiecutter will install :app:`Pyramid` and its dependencies as well. We will still cover many topics of web application development using :app:`Pyramid`, but it's good to know of this facility. This prelude will demonstrate how to get a working :app:`Pyramid` web application running via ``cookiecutter``. |
558f3e
|
8 |
|
SP |
9 |
|
|
10 |
Objectives |
|
11 |
========== |
|
12 |
|
|
13 |
- Use a cookiecutter to make a new project. |
|
14 |
|
|
15 |
- Start up a :app:`Pyramid` application and visit it in a web browser. |
|
16 |
|
|
17 |
|
|
18 |
Steps |
|
19 |
===== |
|
20 |
|
|
21 |
#. Install cookiecutter into your virtual environment. |
|
22 |
|
|
23 |
.. code-block:: bash |
|
24 |
|
|
25 |
$VENV/bin/pip install cookiecutter |
|
26 |
|
28e688
|
27 |
#. Let's use the cookiecutter ``pyramid-cookiecutter-starter`` to create a starter :app:`Pyramid` project in the current directory, entering values at the prompts as shown below for the following command. |
558f3e
|
28 |
|
SP |
29 |
.. code-block:: bash |
|
30 |
|
0080e9
|
31 |
$VENV/bin/cookiecutter gh:Pylons/pyramid-cookiecutter-starter --checkout 1.10-branch |
558f3e
|
32 |
|
SP |
33 |
If prompted for the first item, accept the default ``yes`` by hitting return. |
|
34 |
|
2cd381
|
35 |
.. code-block:: text |
SP |
36 |
|
28e688
|
37 |
You've cloned ~/.cookiecutters/pyramid-cookiecutter-starter before. |
2cd381
|
38 |
Is it okay to delete and re-clone it? [yes]: yes |
SP |
39 |
project_name [Pyramid Scaffold]: cc_starter |
6ff6fa
|
40 |
repo_name [cc_starter]: cc_starter |
2cd381
|
41 |
Select template_language: |
SP |
42 |
1 - jinja2 |
|
43 |
2 - chameleon |
6204d8
|
44 |
3 - mako |
6b6d0e
|
45 |
Choose from 1, 2, 3 [1]: 1 |
SM |
46 |
Select backend: |
|
47 |
1 - none |
|
48 |
2 - sqlalchemy |
|
49 |
3 - zodb |
6204d8
|
50 |
Choose from 1, 2, 3 [1]: 1 |
558f3e
|
51 |
|
SP |
52 |
#. We then run through the following commands. |
|
53 |
|
|
54 |
.. code-block:: bash |
|
55 |
|
|
56 |
# Change directory into your newly created project. |
e6e8bf
|
57 |
cd cc_starter |
558f3e
|
58 |
# Create a new virtual environment... |
e6e8bf
|
59 |
python3 -m venv env |
558f3e
|
60 |
# ...where we upgrade packaging tools... |
e6e8bf
|
61 |
env/bin/pip install --upgrade pip setuptools |
558f3e
|
62 |
# ...and into which we install our project. |
e6e8bf
|
63 |
env/bin/pip install -e . |
558f3e
|
64 |
|
SP |
65 |
#. Start up the application by pointing :app:`Pyramid`'s ``pserve`` command at the |
|
66 |
project's (generated) configuration file: |
|
67 |
|
|
68 |
.. code-block:: bash |
|
69 |
|
e6e8bf
|
70 |
env/bin/pserve development.ini --reload |
558f3e
|
71 |
|
SP |
72 |
On start up, ``pserve`` logs some output: |
|
73 |
|
|
74 |
.. code-block:: text |
|
75 |
|
|
76 |
Starting subprocess with file monitor |
|
77 |
Starting server in PID 73732. |
|
78 |
Serving on http://localhost:6543 |
|
79 |
Serving on http://localhost:6543 |
|
80 |
|
|
81 |
#. Open http://localhost:6543/ in your browser. |
|
82 |
|
|
83 |
Analysis |
|
84 |
======== |
|
85 |
|
|
86 |
Rather than starting from scratch, a cookiecutter can make it easy to get a Python |
6b6d0e
|
87 |
project containing a working :app:`Pyramid` application. |
558f3e
|
88 |
|
SP |
89 |
``pserve`` is :app:`Pyramid`'s application runner, separating operational details from |
|
90 |
your code. When you install :app:`Pyramid`, a small command program called ``pserve`` |
|
91 |
is written to your ``bin`` directory. This program is an executable Python |
|
92 |
module. It is passed a configuration file (in this case, ``development.ini``). |