-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 10/08/2014 05:09 AM, Ivan Sergio Borgonovo wrote:
> On 10/08/2014 10:06 AM, tonthon wrote:
>> Hi,
> 
>> A module's includeme function is called when the module is included 
>> using config.include:
>> 
>> See 
>> http://docs.pylonsproject.org/docs/pyramid/en/latest/api/config.html#module-pyramid.config
>>
>> 
to learn more about the config.include method.
> 
> The nearest thing I was able to write is something like:
> 
> ## main.py ## ...
> 
> import views
> 
> if __name__ == '__main__': config = Configurator() config.scan() 
> config.include(views)
> 
> ...
> 
> ## views.py ## def includeme(config): config.add_route(...) def
> a_view(request): pass config.add_view(...)  It's a bit awkward to
> define the views inside includeme() but it works, I was expecting some
> scope issue.
> 
> The problem is once you wrap the views in a class I still haven't
> been able to think a way to place the routes really near to the views 
> definitions.
> 
> Still at least I can keep routes and views in the same file.

You can still use the 'view_config' decorator while defining the route
in 'includeme'::


- ---------------- %< __init__.py >%-------------------
from pyramid.config import Configurator


def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(settings=settings)
    config.include('pyramid_chameleon')
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.include('.views')
    config.scan()
    return config.make_wsgi_app()


  from pyramid.view import view_config
- ---------------- %< __init__.py >%-------------------


- ---------------- %< views.py >%-------------------
@view_config(route_name='home', renderer='templates/mytemplate.pt')
def my_view(request):
    return {'project': 'foo'}

def includeme(config):
    config.add_route('home', '/')
- ---------------- %< views.py >%-------------------



Tres.
- -- 
===================================================================
Tres Seaver          +1 540-429-0999          [email protected]
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAlQ37PcACgkQ+gerLs4ltQ7wWACgvH+uh5kvufNtWuWLKEk/fZaX
rZoAnRJEw0eFMFmic5mKL/EkPqhcXAke
=CXDp
-----END PGP SIGNATURE-----

-- 
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/d/optout.

Reply via email to