How to use several dispatchers in one application?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use several dispatchers in one application?

Andrew Stromnov

How to mix up two or more CherryPy dispatchers? For example: standard
Dispatcher() for static parts ("/", "/about", "/contacts", etc.), and
RoutesDispatcher() for heavy dynamic parts ("/news/", "/store/", etc).


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-devel
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to use several dispatchers in one application?

Sylvain Hellegouarch

Andrew Stromnov wrote:
> How to mix up two or more CherryPy dispatchers? For example: standard
> Dispatcher() for static parts ("/", "/about", "/contacts", etc.), and
> RoutesDispatcher() for heavy dynamic parts ("/news/", "/store/", etc).
>

dispatcher = cherrypy.dispatche.RooutesDispatcher()
conf = {'/news': 'request.dispatch': dispatcher,
        '/store': 'request.dispatch': dispatcher}
cherrypy.tree.mount(app, '/', config=conf)

By default the default dispatcher will be called apart from the ones in
conf.

- Sylvain

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-devel
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to use several dispatchers in one application?

Andrew Stromnov

On 2/25/07, Sylvain Hellegouarch <[hidden email]> wrote:
> dispatcher = cherrypy.dispatche.RooutesDispatcher()
> conf = {'/news': 'request.dispatch': dispatcher,
>         '/store': 'request.dispatch': dispatcher}
> cherrypy.tree.mount(app, '/', config=conf)
>
> By default the default dispatcher will be called apart from the ones in
> conf.
>
> - Sylvain

Thank you!


it works!
------------------
import cherrypy

class App:
    @cherrypy.expose
    def default(self, *args, **kwargs):
        return "default(args=%s, kwargs=%s)" % (args, kwargs)

class City:
    def __init__(self, name):
        self.name = name
        self.population = 10000

    def index(self, **kwargs):
        return "Welcome to %s, pop. %s" % (self.name, self.population)

if __name__ == '__main__':
    dispatcher = cherrypy.dispatch.RoutesDispatcher()
    dispatcher.connect(
        name='hounslow',
        route=':section/hounslow',
        controller=City("Hounslow"))
    conf = {'/cities': {'request.dispatch': dispatcher},
            '/oldcities': {'request.dispatch': dispatcher}}
    app = cherrypy.Application(App())
    cherrypy.tree.mount(app, '/', config=conf)
    cherrypy.server.quickstart()
    cherrypy.engine.start()
--------

PS. It seems strange, but test/test_routes.py fails on my WinXP +
Python 2.4 + CherryPy (r1623) + Routes (r332)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-devel
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to use several dispatchers in one application?

Sylvain Hellegouarch


>
> PS. It seems strange, but test/test_routes.py fails on my WinXP +
> Python 2.4 + CherryPy (r1623) + Routes (r332)

Could you report the bug with a traceback please?

- Sylvain

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-devel
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to use several dispatchers in one application?

Andrew Stromnov

On 2/25/07, Sylvain Hellegouarch <[hidden email]> wrote:
> Could you report the bug with a traceback please?

Yes. Here it is - http://cherrypy.org/ticket/663 .

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cherrypy-devel" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cherrypy-devel
-~----------~----~----~----~------~----~------~--~---