doc/book/pyramid/quickstart.rst
author Denis Laxalde <denis.laxalde@logilab.fr>
Fri, 27 Jan 2017 11:05:07 +0100
changeset 11945 ef6b18c56b5a
parent 11631 faf279e33298
child 12097 78a5c6a64fad
permissions -rw-r--r--
[skeleton] Add an entry point and configuration for running a Pyramid application We add a `pyramid_main` function in __init__.py that instantiate the WSGI application using "cubicweb.pyramid"; this is defined as an entry point (in setup.py) so that pserve_ can find it. Alongside comes a development.ini file which includes basic settings so that running a Pyramid+CubicWeb application works (only the "instance=<appid>" may be passed as a command-line argument). Logging is also configured there, but only includes the cube at stake and cubicweb (others could be added if needed). .. _perse: \ http://docs.pylonsproject.org/projects/pyramid/en/1.8-branch/pscripts/pserve.html
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11537
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     1
Quick start
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     2
===========
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     3
11587
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
     4
.. highlight:: bash
11537
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     5
11587
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
     6
Prerequites
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
     7
-----------
11537
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     8
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     9
-   Install everything (here with pip, possibly in a virtualenv)::
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    10
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    11
        pip install pyramid-cubicweb cubicweb-pyramid pyramid_debugtoolbar
11587
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    12
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    13
-   Have a working Cubicweb instance, for example:
11537
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    14
11587
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    15
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    16
    -   Make sure CubicWeb is in user mode::
11537
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    17
11587
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    18
            export CW_MODE=user
11537
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    19
11587
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    20
    -   Create a CubicWeb instance, and install the 'pyramid' cube on it (see
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    21
        :ref:`configenv` for more details on this step)::
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    22
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    23
            cubicweb-ctl create pyramid myinstance
11537
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    24
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    25
-   Edit your ``~/etc/cubicweb.d/myinstance/all-in-one.conf`` and set values for
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    26
    :confval:`pyramid-auth-secret` and :confval:`pyramid-session-secret`.
11631
faf279e33298 Merge with pyramid-cubicweb
Yann Voté <yann.vote@logilab.fr>
parents: 11587
diff changeset
    27
    *required if cubicweb.pyramid.auth and pyramid_cubiweb.session get
11587
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    28
    included, which is the default*
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    29
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    30
From CubicWeb
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    31
-------------
11537
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    32
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    33
-   Start the instance with the :ref:`'pyramid' command <cubicweb-ctl_pyramid>`
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    34
    instead of 'start'::
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    35
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    36
        cubicweb-ctl pyramid --debug myinstance
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    37
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    38
In a pyramid application
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    39
------------------------
caf268942436 Initial documentation.
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    40
11587
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    41
-   Create a pyramid application
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    42
11631
faf279e33298 Merge with pyramid-cubicweb
Yann Voté <yann.vote@logilab.fr>
parents: 11587
diff changeset
    43
-   Include cubicweb.pyramid:
11587
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    44
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    45
    .. code-block:: python
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    46
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    47
        def includeme(config):
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    48
            # ...
11631
faf279e33298 Merge with pyramid-cubicweb
Yann Voté <yann.vote@logilab.fr>
parents: 11587
diff changeset
    49
            config.include('cubicweb.pyramid')
11587
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    50
            # ...
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    51
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    52
-   Configure the instance name (in the .ini file):
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    53
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    54
    .. code-block:: ini
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    55
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    56
        cubicweb.instance = myinstance
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    57
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    58
-   Configure the base-url and https-url in all-in-one.conf to match the ones
18dd303225cd [doc] Document embedding in a pyramid app
Christophe de Vienne <christophe@unlish.com>
parents: 11585
diff changeset
    59
    of the pyramid configuration (this is a temporary limitation).
11945
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    60
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    61
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    62
Usage with pserve
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    63
-----------------
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    64
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    65
To run a Pyramid application using pserve_:
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    66
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    67
::
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    68
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    69
    pserve /path/to/development.ini instance=<appid>
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    70
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    71
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    72
.. _pserve: \
ef6b18c56b5a [skeleton] Add an entry point and configuration for running a Pyramid application
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 11631
diff changeset
    73
    http://docs.pylonsproject.org/projects/pyramid/en/latest/pscripts/pserve.html