If I may chime in on this topic (a bit late as I was away on vacation): Michael Merickel and Tom Willis helped me out a bunch on this very topic 2 years ago: http://stackoverflow.com/questions/9539702/pyramid-resource-in-plain-english Remember to read the comments at the bottom
More often than not, you would go for URL dispatch since it's easy. The power of traversal shines when you have to deal with granular authorization policies and when you have no control over the URL that is created. I've found that using the hybrid approach (URL dispatch together with Traversal) to be really useful. Another thing that threw me off a bit, was what you referred to as the callback, the groupfinder function. The examples in the docs don't really say this, but the group finder should be a function that queries your backend database for the groups that a user belongs to (eg. Administrator, Developer, Manager). This wasn't so clear when I was reading the docs 2 years ago. Traversal is beautiful and I think it is this that separates Pyramid from the rest of the frameworks, and not just Python frameworks. Embrace it with open arms and reap the rewards of using it. On Sunday, 15 September 2013 20:44:06 UTC+8, Paul Everitt wrote: > > > > On 9/15/13 1:01 AM, Chung WONG wrote: > > thanks for all of your help, I learned a lot from the replies and have a > > basic understand how traversal works now. > > > > However, I have a question about the view lookup in pyramid with > traversal. > > For example, in Paul's tutorial< > http://docs.pylonsproject.org/projects/pyramid_tutorials/en/latest/humans/resources/step04/index.html> > > , > > in the views.py, there is an view named *add_folder*. It can be access > via* > > *http://127.0.0.1:8080/add_folder > > However, as the context is Folder, it can also be accessed via > > http://127.0.0.1:8080/folder1/add_folder > > That said, if I add resource and make a link like > > http://127.0.0.1:8080/x/y/z/a/b/c/folder1/add_folder< > http://127.0.0.1:8080/folder1/add_folder>, > > the 3 URLs mentioned are getting the same view. > > Is it normal in Traversal? As I know this will not happen in URL > Dispatch. > > Indeed, that is not just normal in traversal, it is in fact the whole > point of traversal. :) > > Routes thinks about patterns (sort of like regular expressions.) > Traversal thinks about objects and operations. "add_folder" is the same > add_folder no matter which Folder instance you call it on. > > --Paul > > > > > Thanks again for the great help > > On Thursday, September 5, 2013 10:18:05 AM UTC+10, Chung WONG wrote: > >> > >> 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.
