Hi, when dealing with traversal, you've got two keypoints : * The context selection (traversing the url) * The view selection
Context selection is done starting in the RootFactory and using the __getitem__ method. The view selection is done through view_predicates that are passed to the view_config call. With traversal, the two key predicates are the context and the name attribute you pass to your view_config call. You'll find more informations on this here : http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/viewconfig.html#predicate-arguments if you only set context, you configure the "default view" (like /a/b/c/ if you provide the 'c' context) if you add a name, you can configure a view for /a/b/c/name_of_my_view. Hope it makes it clearer Regards, Gaston TJEBBES Majerti Le 05/09/2013 02:18, Chung WONG a écrit : > Hi all, > > I have read all the docs available on pyramid's website, however I > still don't really understand how to get a basic traversal app working. > The hello world example is good but I am not able to extend it. The > ZODB wiki is good too but it is a bit too much information to me with > auth and zodb. > What I am trying to do is to add some views to the hello world example > but my understanding is very vague. > I created a starter scaffolding. > > # __init__.py > from pyramid.config import Configurator > *from pyramid.response import Response* > > *class Resource(dict):* > * pass* > * > * > *def get_root(request):* > * return > Resource({'a':Resource({'b':Resource({'c':Resource({'c':Resource()})})})})* > * > * > *def hello_world_of_resources(context,request):* > * output="Here's a resource and its children: %s" % content* > * return Response(output)* > > def main(global_config, **settings): > """ This function returns a Pyramid WSGI application. > """ > config = Configurator(settings=settings,root_factory=get_root) > config.add_static_view('static', 'static', cache_max_age=3600) > * config.add_view(hello_world_of_resources,context=Resource)* > config.scan() > return config.make_wsgi_app() > > > #views.py > from pyramid.view import view_config > *from pyramid.response import Response* > > *@view_config()* > *def my_login(request):* > * return Response('login')* > * > * > *@view_config()* > *def my_logout(request):* > * return Response('logout')* > > I have no clue how to link the resource with the views. Did I miss > something import in the docs or are there any very basic/bare minimum > traversal only tutorial? > Thanks in advance. > > -- > You received this message because you are subscribed to the Google > Groups "pylons-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/pylons-discuss. > For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/pylons-discuss. For more options, visit https://groups.google.com/groups/opt_out.
