Custom Search

Tuesday, November 19, 2013

How to serve an app using python paste

How to serve an app using python paste
###############################


1)
* config.ini

[app:main]
paste.app_factory = service_app:app_factory


2)
* deploy.py

from paste import httpserver
from paste.deploy import loadapp
app = loadapp('config:config.ini', relative_to='.')
httpserver.serve(app, host='127.0.0.1', port='8080')


3)
* service_app.py

def application(environ, start_response):
    """Simple WSGI application"""
    response_headers = [('Content-type','text/plain')]
    status = '200 OK'
    start_response(status, response_headers)
    if environ['PATH_INFO'] == '/login':
    #http://pythonpaste.org/modules/recursive.html
        return ["login page"]
    else:
        return ['Hello world']

def app_factory(global_config, **local_config):
    """This function wraps our simple WSGI app so it
    can be used with paste.deploy"""
    return application

4)
How to run

#python deploy.py
serving on http://127.0.0.1:8080

5)
goto the urls

http://127.0.0.1:8080
http://127.0.0.1:8080/login

1 comment:

  1. http://pythonpaste.org/do-it-yourself-framework.html

    http://pythonpaste.org/deploy/

    http://docs.repoze.org/moonshining/tools/paste.html <==== IMP

    app_factory example
    http://lionfacelemonface.wordpress.com/2011/03/30/wsgi-and-paste-deploy-the-bare-necessities/

    openstack & wsgi
    http://www.slideshare.net/lhrc_mikeyp/openstack-apis-and-wsgi <====IMP

    http://pythonpaste.org/modules/recursive.html

    ReplyDelete