Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 52 lines (38 sloc) 2.11 kb
c469d2d Chris McDonough add raw incremental porting stuff
mcdonc authored
1 Porting an Existing WSGI Application to Pyramid
2 -----------------------------------------------
3
4 Pyramid is cool, but already-working code is cooler. You may not have the
5 time, money or energy to port an existing Pylons, Django, Zope, or other
6 WSGI-based application to Pyramid wholesale. In such cases, it can be useful
7 to *incrementally* port an existing application to Pyramid.
8
9 The broad-brush way to do this is:
10
11 - Set up an *exception view* that will be called whenever a NotFound
12 exception is raised by Pyramid.
13
14 - In this exception view, delegate to your already-written WSGI application.
15
16 Here's an example::
17
18 from pyramid.wsgi import wsgiapp2
19 from pyramid.exceptions import NotFound
20
21 if __name__ == '__main__':
22 # during Pyramid configuration (usually in your Pyramid project's
23 # __init__.py), get a hold of an instance of your existing WSGI
24 # application.
25 original_app = MyWSGIApplication()
26
27 # using the pyramid.wsgi.wsgiapp2 wrapper function, wrap the
28 # application into something that can be used as a Pyramid view.
29 notfound_view = wsgiapp2(original_app)
30
31 # in your configuration, use the wsgiapp2-wrapped application as
32 # a NotFound exception view
33 config = Configurator()
34
35 # ... your other Pyramid configuration ...
36 config.add_view(notfound_view, context=NotFound)
37 # .. the remainder of your configuration ...
38
39
40 When Pyramid cannot resolve a URL to a view, it will raise a NotFound
41 exception. The ``add_view`` statement in the example above configures
42 Pyramid to use your original WSGI application as the NotFound view. This
43 means that whenever Pyramid cannot resolve a URL, your original application
44 will be called.
45
46 Incrementally, you can begin moving features from your existing WSGI
47 application to Pyramid; if Pyramid can resolve a request to a view, the
48 Pyramid "version" of the application logic will be used. If it cannot, the
49 original WSGI application version of the logic will be used. Over time, you
50 can move *all* of the logic into Pyramid without needing to do it all at
51 once.
Something went wrong with that request. Please try again.