summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-05-04 19:56:00 -0400
committerChris McDonough <chrism@plope.com>2012-05-04 19:56:00 -0400
commit5d0989efeb3eecd4cc55fd9c1dcaf1134ced56b2 (patch)
treea29eb5c2ca541e5d7371f859b87dc3fb2658345c /docs
parentcfabb1bbd36d6614eff6576cd87598de5af376c1 (diff)
downloadpyramid-5d0989efeb3eecd4cc55fd9c1dcaf1134ced56b2.tar.gz
pyramid-5d0989efeb3eecd4cc55fd9c1dcaf1134ced56b2.tar.bz2
pyramid-5d0989efeb3eecd4cc55fd9c1dcaf1134ced56b2.zip
add introspection to whats unique
Diffstat (limited to 'docs')
-rw-r--r--docs/narr/introduction.rst28
-rw-r--r--docs/narr/introspector.rst2
2 files changed, 29 insertions, 1 deletions
diff --git a/docs/narr/introduction.rst b/docs/narr/introduction.rst
index 8f7b17dc3..2d04a4f5a 100644
--- a/docs/narr/introduction.rst
+++ b/docs/narr/introduction.rst
@@ -801,6 +801,34 @@ within a function called when another user uses the
See also :ref:`add_directive`.
+Programmatic Introspection
+--------------------------
+
+If you're building a large system that other users may plug code into, it's
+useful to be able to get an enumeration of what code they plugged in *at
+application runtime*. For example, you might want to show them a set of tabs
+at the top of the screen based on an enumeration of views they registered.
+
+This is possible using Pyramid's :term:`introspector`.
+
+Here's an example of using Pyramid's introspector from within a view
+callable:
+
+.. code-block:: python
+ :linenos:
+
+ from pyramid.view import view_config
+ from pyramid.response import Response
+
+ @view_config(route_name='bar')
+ def show_current_route_pattern(request):
+ introspector = request.registry.introspector
+ route_name = request.matched_route.name
+ route_intr = introspector.get('routes', route_name)
+ return Response(str(route_intr['pattern']))
+
+See also :ref:`using_introspection`.
+
Testing
~~~~~~~
diff --git a/docs/narr/introspector.rst b/docs/narr/introspector.rst
index 74595cac8..6bfaf11c0 100644
--- a/docs/narr/introspector.rst
+++ b/docs/narr/introspector.rst
@@ -32,7 +32,7 @@ callable:
from pyramid.response import Response
@view_config(route_name='bar')
- def route_accepts(request):
+ def show_current_route_pattern(request):
introspector = request.registry.introspector
route_name = request.matched_route.name
route_intr = introspector.get('routes', route_name)