Removed extra indentation from some examples (:linenos: should be indented with the same indentation as the rest of the code block)
| | |
| | | The contents of ``config.py``: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | L = [] |
| | | |
| | |
| | | example custom event classes: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | class DocCreated(object): |
| | | def __init__(self, doc, request): |
| | |
| | | event with a decorator: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.events import subscriber |
| | | from .events import DocCreated |
| | |
| | | accessed as ``request.registry.notify``. For example: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from .events import DocCreated |
| | | |
| | |
| | | ``configure_views`` configuration method: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | def configure_views(config): |
| | | config.add_view('theoriginalapp.views.theview', name='theview') |
| | |
| | | that can be used for this purpose. For example: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.events import subscriber |
| | | from pyramid.events import BeforeRender |
| | |
| | | You can write the tween factory as a simple closure-returning function: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | def simple_tween_factory(handler, registry): |
| | | # one-time configuration code goes here |
| | |
| | | method: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | class simple_tween_factory(object): |
| | | def __init__(handler, registry): |
| | |
| | | request: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | # in a module named myapp.tweens |
| | | |
| | |
| | | Pyramid application: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.config import Configurator |
| | | config = Configurator() |
| | |
| | | request handler function. For example: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.config import Configurator |
| | | |
| | |
| | | method. For example: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | class ContentTypePredicate(object): |
| | | def __init__(self, val, config): |
| | |
| | | event type. |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | class RequestPathStartsWith(object): |
| | | def __init__(self, val, config): |
| | |
| | | :meth:`~pyramid.config.Configurator.add_subscriber`: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | # define a subscriber in your code |
| | | |
| | |
| | | :class:`~pyramid.events.subscriber`. |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.events import subscriber |
| | | |
| | |
| | | declarations that look like this: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | # config is an instance of pyramid.config.Configurator |
| | | |
| | |
| | | application's ``setup.py`` file: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | setup(name="mypackage", |
| | | # ... |
| | |
| | | that look something like the following: |
| | | |
| | | .. code-block:: ini |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | [compile_catalog] |
| | | directory = myproject/locale |
| | |
| | | instead, change the ``setup.cfg`` file stanzas to look like so: |
| | | |
| | | .. code-block:: ini |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | [compile_catalog] |
| | | directory = myproject/locale |
| | |
| | | Here's an implementation of a simple locale negotiator: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | def my_locale_negotiator(request): |
| | | locale_name = request.params.get('my_locale') |
| | |
| | | ``render_to_response`` call: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.renderers import render_to_response |
| | | |
| | |
| | | You can return a Python dictionary: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.view import view_config |
| | | |
| | |
| | | callable: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.view import view_config |
| | | from pyramid.response import Response |
| | |
| | | callable: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.view import view_config |
| | | from pyramid.response import Response |
| | |
| | | For example: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | route_intr = introspector.get('routes', 'edit_user') |
| | | pattern = route_intr['pattern'] |
| | |
| | | methods on it. |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | import logging |
| | | log = logging.getLogger(__name__) |
| | |
| | | Here's a sample resource tree, represented by a variable named ``root``: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | class Resource(dict): |
| | | pass |
| | |
| | | defining your scaffold template: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | try: # pyramid 1.0.X |
| | | # "pyramid.paster.paste_script..." doesn't exist past 1.0.X |
| | |
| | | pyramid.view import static``) that is causing the problem: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.view import view_config |
| | | |
| | |
| | | do things the newer way: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.view import view_config |
| | | |
| | |
| | | result in a particular view callable being invoked: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | config.add_route('idea', 'site/{id}') |
| | | config.add_view('mypackage.views.site_view', route_name='idea') |
| | |
| | | which you started the application from. For example: |
| | | |
| | | .. code-block:: text |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | $ PYRAMID_DEBUG_ROUTEMATCH=true $VENV/bin/pserve development.ini |
| | | Starting server in PID 13586. |
| | |
| | | instance, a predicate might do some type conversion of values: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | def integers(*segment_names): |
| | | def predicate(info, request): |
| | |
| | | expressions specifying requirements for that marker. For instance: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | def integers(*segment_names): |
| | | def predicate(info, request): |
| | |
| | | the route in a set of route predicates: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | def twenty_ten(info, request): |
| | | if info['route'].name in ('ymd', 'ym', 'y'): |
| | |
| | | is below: |
| | | |
| | | .. code-block:: apache |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | NameVirtualHost *:80 |
| | | |
| | |
| | | the same can be achieved using ``SetEnv``: |
| | | |
| | | .. code-block:: apache |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | <Location /> |
| | | SetEnv HTTP_X_VHM_ROOT /cms |
| | |
| | | e.g.: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :linenos: |
| | | |
| | | from pyramid.response import Response |
| | | |
| | |
| | | ``edit_page()``, for example: |
| | | |
| | | .. code-block:: python |
| | | :linenos: |
| | | :emphasize-lines: 3 |
| | | :linenos: |
| | | :emphasize-lines: 3 |
| | | |
| | | @view_config(name='add_page', context='.models.Wiki', |
| | | renderer='templates/edit.pt', |