title: Pyramid traversal is doing my head in
body: <p>I am trying to get my head around Pyramid traversal with this very simple example.  What I haven't quite grasped yet is where to "inject" an <code>Article</code> object from the db.</p>
  
  <p>As it is, <code>/Article</code> correctly finds and renders the <code>article_view</code> but that's fairly useless.  How/when/where do I use the next part of the URL to query for a particular Article from the db?  eg. <code>/Article/5048230b2485d614ecec341d</code>.</p>
  
  <p>Any clues would be great!</p>
  
  <p><strong>init</strong>.py</p>
  
  <pre><code>from pyramid.config import Configurator
  from pyramid.events import subscriber
  from pyramid.events import NewRequest
  import pymongo
  
  from otk.resources import Root
  
  def main(global_config, **settings):
      """ This function returns a WSGI application.
      """
      config = Configurator(settings=settings, root_factory=Root)
      config.add_static_view('static', 'otk:static')
      # MongoDB
      def add_mongo_db(event):
          settings = event.request.registry.settings
          url = settings['mongodb.url']
          db_name = settings['mongodb.db_name']
          db = settings['mongodb_conn'][db_name]
          event.request.db = db
      db_uri = settings['mongodb.url']
      MongoDB = pymongo.Connection
      if 'pyramid_debugtoolbar' in set(settings.values()):
          class MongoDB(pymongo.Connection):
              def __html__(self):
                  return 'MongoDB: &lt;b&gt;{}&gt;&lt;/b&gt;'.format(self)
      conn = MongoDB(db_uri)
      config.registry.settings['mongodb_conn'] = conn
      config.add_subscriber(add_mongo_db, NewRequest)
      config.include('pyramid_jinja2')
      config.include('pyramid_debugtoolbar')
      config.scan('otk')
      return config.make_wsgi_app()
  </code></pre>
  
  <p>resources.py</p>
  
  <pre><code>class Root(object):
      __name__ = None
      __parent__ = None
  
      def __init__(self, request):
          self.request = request
  
      def __getitem__(self, key):
          if key == 'Article':
              return Article(self.request)
          else:
              raise KeyError
  
  class Article:
      __name__ = ''
      __parent__ = Root
  
      def __init__(self, request):
          self.reqeust = request
  
      # so I guess in here I need to update the Article with
      # with the document I get from the db.  How?
  
      def __getitem__(self, key):
          raise KeyError
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>from pyramid.view import view_config
  from otk.resources import *
  from pyramid.response import Response
  
  @view_config(context=Root, renderer='templates/index.jinja2')
  def index(request):
      return {'project':'OTK'}
  
  @view_config(context=Article, renderer='templates/view/article.jinja2')
  def article_view(context, request):
      # I end up with an instance of Article here as the context.. but 
      # at the moment, the Article is empty
      return {}
  </code></pre>