- Remove calls to config.begin()/config.end() from startup config code in
tutorials and paster templates (no longer required).
| | |
| | | |
| | | - Make test suite pass on PyPy (Chameleon doesn't work). |
| | | |
| | | - Surrounding application configuration with ``config.begin()`` and |
| | | ``config.end()`` is no longer necessary. All paster templates have been |
| | | changed to no longer call these functions. |
| | | |
| | | Documentation |
| | | ------------- |
| | | |
| | | - SQLAlchemy+URLDispatch and ZODB+Traversal tutorials have been updated to |
| | | not call ``config.begin()`` or ``config.end()``. |
| | | |
| | | Bug Fixes |
| | | --------- |
| | | |
| | |
| | | - Use ``@register_view`` instead of ``@view_config`` and change view docs to |
| | | use "view registration" instead of "view configuration". |
| | | |
| | | - Remove calls to config.begin()/config.end() from startup config code in |
| | | tutorials and paster templates (no longer required). |
| | | |
| | | - SQLAlchemy idiomatics: |
| | | |
| | | <RaFromBRC> mcdonc: those paster templates all look pretty good... the |
| | |
| | | Should-Have |
| | | ----------- |
| | | |
| | | - Try to make test suite pass on PyPy, IronPython. |
| | | - Try to make test suite pass on IronPython. |
| | | |
| | | - Add docs for httpexceptions module for each webob.exc class that inherits |
| | | from WSGIHTTPException. |
| | |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | config = Configurator(root_factory=get_root, settings=settings) |
| | | config.begin() |
| | | config.add_view('myproject.views.my_view', |
| | | context='myproject.models.MyModel', |
| | | renderer='myproject:templates/mytemplate.pt') |
| | | config.add_static_view('static', 'myproject:static') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | |
| | | if __name__ == '__main__': |
| | | config = Configurator() |
| | | config.begin() |
| | | config.add_view(hello_world) |
| | | config.end() |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | |
| | | We won't talk much about what this application does yet. Just note |
| | | that the "configuration' statements take place underneath the ``if |
| | | __name__ == '__main__':`` stanza in the form of method calls on a |
| | | :term:`Configurator` object (e.g. ``config.begin()``, |
| | | ``config.add_view(...)``, and ``config.end()``. These statements take |
| | | place one after the other, and are executed in order, so the full |
| | | power of Python, including conditionals, can be employed in this mode |
| | | of configuration. |
| | | We won't talk much about what this application does yet. Just note that the |
| | | "configuration' statements take place underneath the ``if __name__ == |
| | | '__main__':`` stanza in the form of method calls on a :term:`Configurator` |
| | | object (e.g. ``config.add_view(...)``). These statements take place one |
| | | after the other, and are executed in order, so the full power of Python, |
| | | including conditionals, can be employed in this mode of configuration. |
| | | |
| | | .. index:: |
| | | single: view_config |
| | |
| | | if __name__ == '__main__': |
| | | from pyramid.configuration import Configurator |
| | | config = Configurator() |
| | | config.begin() |
| | | config.scan() |
| | | config.end() |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | |
| | |
| | | |
| | | if __name__ == '__main__': |
| | | config = Configurator() |
| | | config.begin() |
| | | config.add_view(hello_world) |
| | | config.add_view(goodbye_world, name='goodbye') |
| | | config.end() |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | |
| | |
| | | |
| | | if __name__ == '__main__': |
| | | config = Configurator() |
| | | config.begin() |
| | | config.add_view(hello_world) |
| | | config.add_view(goodbye_world, name='goodbye') |
| | | config.end() |
| | | app = config.make_wsgi_app() |
| | | serve(app, host='0.0.0.0') |
| | | |
| | |
| | | this particular :app:`Pyramid` application. Methods called on the |
| | | Configurator will cause registrations to be made in a |
| | | :term:`application registry` associated with the application. |
| | | |
| | | Beginning Configuration |
| | | ~~~~~~~~~~~~~~~~~~~~~~~ |
| | | |
| | | .. ignore-next-block |
| | | .. code-block:: python |
| | | |
| | | config.begin() |
| | | |
| | | The :meth:`pyramid.configuration.Configurator.begin` method tells |
| | | the system that application configuration has begun. In particular, |
| | | this causes the :term:`application registry` associated with this |
| | | configurator to become the "current" application registry, meaning |
| | | that code which attempts to use the application registry :term:`thread |
| | | local` will obtain the registry associated with the configurator. |
| | | This is an explicit step because it's sometimes convenient to use a |
| | | configurator without causing the registry associated with the |
| | | configurator to become "current". |
| | | |
| | | .. note:: |
| | | |
| | | See :ref:`threadlocals_chapter` for a discussion about what it |
| | | means for an application registry to be "current". |
| | | |
| | | .. _adding_configuration: |
| | | |
| | |
| | | important. We can register ``goodbye_world`` first and |
| | | ``hello_world`` second; :app:`Pyramid` will still give us the most |
| | | specific callable when a request is dispatched to it. |
| | | |
| | | Ending Configuration |
| | | ~~~~~~~~~~~~~~~~~~~~ |
| | | |
| | | .. ignore-next-block |
| | | .. code-block:: python |
| | | |
| | | config.end() |
| | | |
| | | The :meth:`pyramid.configuration.Configurator.end` method tells the |
| | | system that application configuration has ended. It is the inverse of |
| | | :meth:`pyramid.configuration.Configurator.begin`. In particular, |
| | | this causes the :term:`application registry` associated with this |
| | | configurator to no longer be the "current" application registry, |
| | | meaning that code which attempts to use the application registry |
| | | :term:`thread local` will no longer obtain the registry associated |
| | | with the configurator. |
| | | |
| | | .. note:: |
| | | |
| | | See :ref:`threadlocals_chapter` for a discussion about what it |
| | | means for an application registry to be "current". |
| | | |
| | | .. index:: |
| | | single: make_wsgi_app |
| | |
| | | #. Line 2 imports the ``get_root`` function from |
| | | :mod:`myproject.models` that we use later. |
| | | |
| | | #. Lines 4-14 define a function that returns a :app:`Pyramid` |
| | | #. Lines 4-12 define a function that returns a :app:`Pyramid` |
| | | WSGI application. This function is meant to be called |
| | | by the :term:`PasteDeploy` framework as a result of running |
| | | ``paster serve``. |
| | | |
| | | Within this function, configuration is performed. |
| | | |
| | | Lines 9-11 register a "default view" (a view that has no ``name`` |
| | | Lines 8-10 register a "default view" (a view that has no ``name`` |
| | | attribute). It is registered so that it will be found when the |
| | | :term:`context` of the request is an instance of the |
| | | :class:`myproject.models.MyModel` class. The first argument to |
| | |
| | | ``templates`` directory of the ``myproject`` package. The template file |
| | | it actually points to is a :term:`Chameleon` ZPT template file. |
| | | |
| | | Line 12 registers a static view, which will serve up the files from the |
| | | Line 11 registers a static view, which will serve up the files from the |
| | | ``mypackage:static`` :term:`resource specification` (the ``static`` |
| | | directory of the ``mypackage`` package). |
| | | |
| | | Line 14 returns a :term:`WSGI` application to the caller of the function |
| | | Line 12 returns a :term:`WSGI` application to the caller of the function |
| | | (Paste). |
| | | |
| | | ``views.py`` |
| | |
| | | .. index:: |
| | | \.. index:: |
| | | single: unit testing |
| | | single: integration testing |
| | | |
| | |
| | | factory` and the settings keywords parsed by PasteDeploy. The root |
| | | factory is named ``get_root``. |
| | | |
| | | #. *Lines 16-18*. Begin configuration using the ``begin`` method of |
| | | the :meth:`pyramid.configuration.Configurator` class, load the |
| | | #. *Line 16*. Load the |
| | | ``configure.zcml`` file from our package using the |
| | | :meth:`pyramid.configuration.Configurator.load_zcml` method, and |
| | | end configuration using the |
| | | :meth:`pyramid.configuration.Configurator.end` method. |
| | | :meth:`pyramid.configuration.Configurator.load_zcml` method. |
| | | |
| | | #. *Line 19*. Use the |
| | | #. *Line 17*. Use the |
| | | :meth:`pyramid.configuration.Configurator.make_wsgi_app` method |
| | | to return a :term:`WSGI` application. |
| | | |
| | |
| | | def get_root(request): |
| | | return finder(request.environ) |
| | | config = Configurator(root_factory=get_root, settings=settings) |
| | | config.begin() |
| | | config.load_zcml('configure.zcml') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | |
| | | def get_root(request): |
| | | return finder(request.environ) |
| | | config = Configurator(root_factory=get_root, settings=settings) |
| | | config.begin() |
| | | config.load_zcml('configure.zcml') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | def get_root(request): |
| | | return finder(request.environ) |
| | | config = Configurator(root_factory=get_root, settings=settings) |
| | | config.begin() |
| | | config.load_zcml('configure.zcml') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | def get_root(request): |
| | | return finder(request.environ) |
| | | config = Configurator(root_factory=get_root, settings=settings) |
| | | config.begin() |
| | | config.load_zcml('configure.zcml') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | def get_root(request): |
| | | return finder(request.environ) |
| | | config = Configurator(root_factory=get_root, settings=settings) |
| | | config.begin() |
| | | config.load_zcml('configure.zcml') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | deployment-related values such as ``reload_templates``, |
| | | ``db_string``, etc. |
| | | |
| | | #. *Line 15*. We call :meth:`pyramid.configuration.Configurator.begin` which |
| | | tells the configuration machinery we are starting configuration. |
| | | |
| | | #. *Line 16*. We call |
| | | #. *Line 15*. We call |
| | | :meth:`pyramid.configuration.Configurator.add_static_view` with the |
| | | arguments ``static`` (the name), and ``tutorial:static`` (the path). This |
| | | registers a static resource view which will match any URL that starts with |
| | |
| | | ``/static/foo``) will be used to compose a path to a static file resource, |
| | | such as a CSS file. |
| | | |
| | | #. *Lines 17-18*. Register a :term:`route configuration` via the |
| | | #. *Lines 16-17*. Register a :term:`route configuration` via the |
| | | :meth:`pyramid.configuration.Configurator.add_route` method that will be |
| | | used when the URL is ``/``. Since this route has an ``pattern`` equalling |
| | | ``/`` it is the "default" route. The argument named ``view`` with the |
| | |
| | | ``tutorial.views.my_view`` view returns a dictionary, a :term:`renderer` |
| | | will use this template to create a response. |
| | | |
| | | #. *Line 19*. We call :meth:`pyramid.configuration.Configurator.end` which |
| | | tells the configuration machinery we are ending configuration. |
| | | |
| | | #. *Line 20*. We use the |
| | | #. *Line 18*. We use the |
| | | :meth:`pyramid.configuration.Configurator.make_wsgi_app` method to return |
| | | a :term:`WSGI` application. |
| | | |
| | |
| | | root_factory='tutorial.models.RootFactory', |
| | | authentication_policy=authn_policy, |
| | | authorization_policy=authz_policy) |
| | | config.begin() |
| | | config.add_static_view('static', 'tutorial:static') |
| | | config.add_route('view_wiki', '/', view='tutorial.views.view_wiki') |
| | | config.add_route('login', '/login', |
| | |
| | | config.add_view('tutorial.login.login', |
| | | renderer='tutorial:templates/login.pt', |
| | | context='pyramid.exceptions.Forbidden') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | db_echo = settings.get('db_echo', 'false') |
| | | initialize_sql(db_string, asbool(db_echo)) |
| | | config = Configurator(settings=settings) |
| | | config.begin() |
| | | config.add_static_view('static', 'tutorial:static') |
| | | config.add_route('home', '/', view='tutorial.views.my_view', |
| | | view_renderer='templates/mytemplate.pt') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | | |
| | |
| | | db_echo = settings.get('db_echo', 'false') |
| | | initialize_sql(db_string, asbool(db_echo)) |
| | | config = Configurator(settings=settings) |
| | | config.begin() |
| | | config.add_static_view('static', 'tutorial:static') |
| | | config.add_route('home', '/', view='tutorial.views.my_view', |
| | | view_renderer='templates/mytemplate.pt') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | |
| | | db_echo = settings.get('db_echo', 'false') |
| | | initialize_sql(db_string, asbool(db_echo)) |
| | | config = Configurator(settings=settings) |
| | | config.begin() |
| | | config.add_static_view('static', 'tutorial:static') |
| | | config.add_route('home', '/', view='tutorial.views.view_wiki') |
| | | config.add_route('view_page', '/:pagename', |
| | |
| | | config.add_route('edit_page', '/:pagename/edit_page', |
| | | view='tutorial.views.edit_page', |
| | | view_renderer='tutorial:templates/edit.pt') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | db_echo = settings.get('db_echo', 'false') |
| | | get_root = appmaker(db_string, asbool(db_echo)) |
| | | config = Configurator(settings=settings, root_factory=get_root) |
| | | config.begin() |
| | | config.add_static_view('static', '{{package}}:static') |
| | | config.add_view('{{package}}.views.view_root', |
| | | context='{{package}}.models.MyApp', |
| | |
| | | config.add_view('{{package}}.views.view_model', |
| | | context='{{package}}.models.MyModel', |
| | | renderer="templates/model.pt") |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | | |
| | |
| | | """ |
| | | from pyramid.configuration import Configurator |
| | | config = Configurator(settings=settings) |
| | | config.begin() |
| | | session_factory = session_factory_from_settings(settings) |
| | | config.set_session_factory(session_factory) |
| | | config.add_static_view('static', '{{package}}:static/') |
| | |
| | | action='index') |
| | | config.add_subscriber('{{package}}.lib.subscribers.add_renderer_globals', |
| | | 'pyramid.events.BeforeRender') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | |
| | | """ |
| | | from pyramid.configuration import Configurator |
| | | config = Configurator(settings=settings) |
| | | config.begin() |
| | | session_factory = session_factory_from_settings(settings) |
| | | config.set_session_factory(session_factory) |
| | | config.add_static_view('static', '{{package}}:static/') |
| | |
| | | action='index') |
| | | config.add_subscriber('{{package}}.subscribers.add_renderer_globals', |
| | | 'pyramid.events.BeforeRender') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | "configuration.") |
| | | initialize_sql(db_string, asbool(settings.get('db_echo'))) |
| | | config = Configurator(settings=settings) |
| | | config.begin() |
| | | session_factory = session_factory_from_settings(settings) |
| | | config.set_session_factory(session_factory) |
| | | config.add_static_view('static', '{{package}}:static/') |
| | |
| | | action='index') |
| | | config.add_subscriber('{{package}}.subscribers.add_renderer_globals', |
| | | 'pyramid.events.BeforeRender') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | |
| | | db_echo = settings.get('db_echo', 'false') |
| | | initialize_sql(db_string, asbool(db_echo)) |
| | | config = Configurator(settings=settings) |
| | | config.begin() |
| | | config.add_static_view('static', '{{package}}:static') |
| | | config.add_route('home', '/', view='{{package}}.views.my_view', |
| | | view_renderer='templates/mytemplate.pt') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | | |
| | |
| | | """ This function returns a Pyramid WSGI application. |
| | | """ |
| | | config = Configurator(root_factory=get_root, settings=settings) |
| | | config.begin() |
| | | config.add_view('{{package}}.views.my_view', |
| | | context='{{package}}.models.MyModel', |
| | | renderer='{{package}}:templates/mytemplate.pt') |
| | | config.add_static_view('static', '{{package}}:static') |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | """ |
| | | zcml_file = settings.get('configure_zcml', 'configure.zcml') |
| | | config = Configurator(root_factory=get_root, settings=settings) |
| | | config.begin() |
| | | config.load_zcml(zcml_file) |
| | | config.end() |
| | | return config.make_wsgi_app() |
| | | |
| | |
| | | def get_root(request): |
| | | return finder(request.environ) |
| | | config = Configurator(root_factory=get_root, settings=settings) |
| | | config.begin() |
| | | config.load_zcml(zcml_file) |
| | | config.end() |
| | | return config.make_wsgi_app() |