django’s urlconf for webware

December 3, 2007 – 21:51

It appears to be quite easy (from technical side) to do a coup refactoring an application from webware to django.

As a first step could be substituting default webware url mapper from url-maps-to-file-hierarchy to django-like regexp matcher.

url map would look like familiar django file:

from django.conf.urls.defaults import patterns
from Pages import Main

urlpatterns = patterns(
    '',
    (r'^$', Main.Main),
)

where Pages.Main is a webware servlet (e.g. a Cheetah compiled page).

To make it work, add a custom urlParser for a module. For the example above, it could well be in Pages/__ init __.py. That parser would use django urlconf module to parse an url in an incoming request:

class UrlConfParser:
    'django urlconf-like URLParser for WebWare'

    def parse(self, trans, requestPath):
        'parse request'
        from urls import urlpatterns

        for pattern in urlpatterns:
            res = pattern.resolve(requestPath)
            if res:
                return res[0]
        return

That’s it! Just make sure that you’re mapping urls to good old webware servlets – that’s what the caller expects.