Porting a Legacy Pylons Application Piecemeal¶
You would like to move from Pylons 1.0 to Pyramid, but you're not going to be able manage a wholesale port any time soon. You're wondering if it would be practical to start using some parts of Pyramid within an existing Pylons project.
One idea is to use a Pyramid "NotFound view" which delegates to the existing Pylons application, and port piecemeal:
1# ... obtain pylons WSGI application object ... 2from mypylonsproject import thepylonsapp 3 4class LegacyView(object): 5 def __init__(self, app): 6 self.app = app 7 def __call__(self, request): 8 return request.get_response(self.app) 9 10if __name__ == '__main__': 11 legacy_view = LegacyView(thepylonsapp) 12 config = Configurator() 13 config.add_view(context='pyramid.exceptions.NotFound', view=legacy_view) 14 # ... rest of config ...
At that point, whenever Pyramid cannot service a request because the URL doesn't match anything, it will invoke the Pylons application as a fallback, which will return things normally. At that point you can start moving logic incrementally into Pyramid from the Pylons application until you've ported everything.