I have implemented a global appIncluder function which is imported as
includeme with the *init*.py of the package to be included.
includeme (appIncluder) receives the config object, so it is then easy to
use config.package and its variables/methods/classes (present in the same *
init*.py and submodules.
The code:
project: 'foo' apps to be deployed in foo.foo.apps directory
Structure:
foo|-foo
|- __init__.py
|- appincluder.py
|-apps
|-test
|- __init__.py
|- views.py
|- templates
|- test.jinja2
foo/foo/*init*.py:
config.include('foo.apps.test')
foo/foo/appincluder.py
def appIncluder(config):
app = config.package
prefix = app.prefix
routes = app.routes
for route,url in routes.items():
config.add_route(route,prefix + url)
config.scan(app)
log.info('app: %s included' % app.__name__)
foo/foo/apps/test/*init*.py
from foo.appincluder import appIncluder as includeme
prefix = '/test'
routes = {
'test': '/home'}
foo/foo/apps/test/views.py
from pyramid.view import view_config
@view_config(route_name='test', renderer='templates/test.jinja2')def
test(request):
return {}
I hope it helps someone.
--
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.