[Web-SIG] using WSGI for standard pluggable applications
Ian Bicking
ianb at colorstudy.com
Sat Sep 10 19:54:07 CEST 2005
Ksenia Marasanova wrote:
> Sorry if this is a trivial question, but does it sounds reasonable to
> use WSGI for "pluggable" standard applications, instead of usual
> Python imports? For example, standard news module, like:
>
> app = NewsApp(path='/site/news/')
>
> The content of news app would be inserted into site template,
> generated by main publisher. If there are any examples of such WSGI
> use, I'll be glad to hear that...
I think you are describing something along the lines of what Paste
Deploy is doing (http://pythonpaste.org/deploy/paste-deploy.html).
It uses Eggs with entry points (though plain imports are also allowed).
So if you have a news application, you'd add this to its setup.py:
setup(
name="NewsApp", ...
entry_points={
'paste.app_factory': 'main=news.wsgiapp:make_app'})
news.wsgiapp looks like:
def make_app(global_conf, database):
# database is a required configuration variable specific to news
# you return a plain WSGI application here
Then to deploy it, you create a configuration file (lets say site.ini):
[composit:main]
use = egg:Paste#urlmap
/site/news = news
/site/wiki = wiki
/ = static
[app:news]
use = egg:NewsApp
database = sqlite:/path/to/db
[app:wiki]
use = egg:MoinMoin
[app:static]
use = egg:Paste#static
document_root = /var/www
Then to use the configuration file you do:
from paste.deploy import loadapp
app = loadapp('config:/path/to/site.ini')
# app is now a WSGI application that dispatches
# based on URL to the three configured applications
Or you can do:
paster serve site.ini
At least this will work if you define a server in the config file, like:
[server:main]
use = egg:PasteScript#wsgiutils
port = 8000
More information about the Web-SIG
mailing list