My internal understanding of this may not be very helpful or complete
but think of it this way:
for any request there is
- context
- the rendered view
What you are doing in get_root is saying that if someone requests:
/a/b/c/c/
- the context is the very last Resource in the get_root expression and
- the view is hello_world_of_resources (because you hooked it up with
add_view)
What is happening here is that the context is being setup and then
passed to the actual view for use. You may or may not choose to use the
context in the view.
If you had only only requested /a the context would have been the very
first resource object in the get_root expression and that is what would
be passed to hello_world...
To hookup your my_login, my_logout you would either:
- use config.add_view (the same as in the example for
hello_world_of_resources)
- or specify the context in the view_config decorator. (config.scan will
pick it up)
if I understand correctly, once you do that and request say -
/a/b/my_login, the view will be invoked with the appropriate context. Of
course if you simply call /my_login then the context is the root context.
HTH
AM
On 09/04/2013 05:18 PM, 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.
--
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.