citykid
citykid

Reputation: 11040

Django url routing - include url part for dispatching

can i substitute the 2 url routes

urlpatterns = patterns('',        
    url(r'service/geticons', 'core.service.geticons'),
    url(r'service/getnearby', 'core.service.getnearby'),

by a single, more generic, route that routes all requests to the function in the service module with the name of the last url segment?

thinking about something like

    url(r'service/#f', 'core.service.#f')

or must i do such dispatch in the service module in django?

Upvotes: 0

Views: 291

Answers (1)

Sure, you could collect the path and point it to a view that returns the function.

url(r'service/(?P<function>\w+)/$', 'core.service.function_router')


def function_router(request, function):
    return globals()[function](request)

But, it's probably better just to explicitly set the urls.

Upvotes: 1

Related Questions