Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
100644 35 lines (28 sloc) 1.791 kb
e280033 @mikeorr Pyramid/Pylons Guide: launch and main pages.
mikeorr authored
1 The Main Function
2 +++++++++++++++++
4 Both Pyramid and Pylons have a top-level function that returns a WSGI
5 application. The Pyramid function is ``main`` in *pyramidapp/\_\_init\_\*.
6 The Pylons function is ``make_app`` in *pylonsapp/config/*. Here's
7 the main function generated by Pyramid's 'starter' scaffold:
10 .. literalinclude:: examples/
11 :linenos:
13 Pyramid has less boilerplate code than Pylons, so the main function subsumes
14 Pylons',, *and* modules. Some people
15 like to put their route definitions in a separate module, but that's a personal
16 choice. The point is that Pyramid's ``main`` function has just 5 Python
17 statements out of the box, while Pylons' ``make_app`` 16 -- or 35 if you
18 include and
20 Most of the ``main`` function deals with the Configurator (``config``). It's
21 not the application object; it's a helper class which configures the
22 application object. You instantiate the Configurator by passing the deployment
23 settings as keyword args, and call methods to set up routes, views, and other
24 things. Finally you call ``config.make_wsgi_app()`` to get the application,
25 and return it. The application is an instance of ``pyramid.router.Router``. (A
26 Pylons application is an instance of a ``PylonsApp`` subclass.)
28 We'll discuss the route and view methods in their respective chapters, so
29 there's not much more to say here. But we'll close with a quick look at how you
30 can use the main function. The normal way is to run "pserve", which
31 automatically calls it. But you can also call it directly in Python code; for
32 instance to use it with a custom server or testing environment, or with
33 mod_wsgi. You could also wrap the application in WSGI middleware before
34 returning it.
Something went wrong with that request. Please try again.